Q:

C++ - program for Array of Structure.

belongs to collection: C++ programs on various topics

0

C++ - program for Array of Structure.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C++ program - Demonstrate Example of Array of Structures

/*C++ - program for Array of Structure.*/

#include <iostream>
#include <iomanip>

using namespace std;

#define MAX 100
struct student{
	char name[30];
	int rollNumber;
};

int main(){
	struct student std[MAX];
	int n,loop;

	cout<<"Enter total number of students: ";
	cin>>n;

	for(loop=0; loop<n; loop++){
		cout<<"Enter name:";
		cin.ignore(1);
		cin.getline(std[loop].name,30);
		cout<<"Enter roll number:";
		cin>>std[loop].rollNumber;
	}

	cout<<"Entered records are:"<<endl;
	cout<<setw(30)<<"Name"<<setw(20)<<"Roll Number"<<endl;

	for(loop=0; loop<n; loop++){
		cout<<setw(30)<<std[loop].name<<setw(10)<<std[loop].rollNumber<<endl;
	}
	
	return 0;
}
Enter total number of students: 2
Enter name:Mike
Enter roll number:101
Enter name:Monty            
Enter roll number:102
Entered records are:
                     Name         Roll Number
                          Mike       101

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to demonstrate calling of private memb... >>
<< C++ - program for Nested Structure (Structure with...