#include<iostream>
#include<conio.h>
#include<string>
#include<iomanip>
using namespace std;
struct Records
{
string name;
int age;
};
void getInfo(Records files[], int SIZE);
void displayInfo(Records files[], int SIZE);
const int SIZE = 50;
int numRec = 0;
int main()
{
// Declare an array of objects.
Records files[SIZE];
cout << "Max amount of files you can enter is " << SIZE << ".\n";
cout << "\nHow many records do you want to enter?: ";
cin >> numRec;
cout << endl;
if (numRec <= SIZE)
{
getInfo(files, SIZE);
cout << endl;
}
else
{
cout << "You can only enter less than " << SIZE << " records!\n\n";
exit(0);
}
displayInfo(files, SIZE);
return 0;
}
void getInfo(Records files[], int SIZE)
{
for (int i = 0; i < numRec; i++)
{
cout << "Name: ";
cin >> files[i].name;
cout << setw(6) << "Age: ";
cin >> files[i].age;
cout << endl;
}
}
void displayInfo(Records files[], int SIZE)
{
int count = 1;
cout << "Here are the records you entered:\n\n";
for (int i = 0; i < numRec; i++)
{
cout << "Object#" << count << ":\n";
cout << "NAME: " << files[i].name << endl;
cout << setw(6) << "AGE: " << files[i].age << endl;
cout << endl;
count++;
getch();
}
}
This post has been edited by Salem_c: 08 July 2012 - 01:10 AM

New Topic/Question
Reply



MultiQuote




|