Answer to Question #205920 in C++ for Daniyal Anwar khan

Question #205920

Write a program to define four structures with structure variable of array types. Enter data into each structure variable that has four records and each record contains five fields.


1
Expert's answer
2021-06-11T07:41:27-0400
#include <iostream>
#include <cstring>

using namespace std;

struct student
{
  int roll_no;
  string name;
  int phone_number;
};

int main(){

	struct student stud[5];
  	int i;

	for(i=0; i<5; i++){                   		//taking values from user
		cout << "Student " << i + 1 << endl;
		cout << "Enter roll no" << endl;
		cin >> stud[i].roll_no;
		cout << "Enter name" << endl;
		cin >> stud[i].name;
		cout << "Enter phone number" << endl;
		cin >> stud[i].phone_number;
	}

	for(i=0; i<5; i++){							//printing values
		cout << "Student " << i + 1 << endl;
		cout << "Roll no : " << stud[i].roll_no << endl;
		cout << "Name : " << stud[i].name << endl;
		cout << "Phone no : " << stud[i].phone_number << endl;
	}
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog