Advertisements
Advertisements
Question
Debug the error in the following program.
#include <istream.h>
structPersonRec
{
charlastName[10];
chaefirstName[10];
int age;
}
PersonRecPeopleArrayType[10];
void main()
{
PersonRecord people;
for (i = 0; i < 10; i++)
{
cout<<people.firstName<< ‘ ‘ <<people.lastName <<people.age;
}
for (int i = 0; i < 10; i++)
{
cout<< "Enter first name: "; cin<<peop[i].firstName;
cout<< "Enter last name: "; cin>>peop[i].lastName;
cout<< "Enter age: "; cin>> people[i].age;}
}
Answer in Brief
Solution
Corrected Program:
#include<istream.h>
#include<iomanip>
using namespace std;
struct PersonRee
{
char lastName[10];
char firstName[10]; int age;
}
PersonRecPeople[10];
VoidLoadArray();
int main()
{
Load Array();
for(i = 0; i<=10, i++)
{
cout<<people[i]. firstname;
cout<<people[i]. lastname;
cout<<setw(10)<<people[i].age<<endl;
}
}
VoidLoadArray()
{
for (int i = 0; i<10; i++)
{
cout<<"Enter first name:";
cin>>people[i].firstName;
cout<<"Enter last name:";
cin>>people[i].lastName;
cout<<"Enter age";
cin>>people[i].age;
}
}
shaalaa.com
Is there an error in this question or solution?