Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Write an array of 10 students in the collage. Write two functions; one for input, second for output and determine following in main() (a) write a program to print names of all students who joined in a particular year. (b) Write a program to print the data of a student whose roll number is given assignment
#include <iostream>
#include <string>
#include<conio.h>
#include<iomanip>
using namespace std;
//Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year
struct Student{
int RollNumber;
string Name;
string Department;
string Course;
int Year;
};
void getStudentsInfo(struct Student students[]);
void displaytStudentsInfo(struct Student students[]);
void displaytStudentsInfoOfGivenAssignment(struct Student students[],int rollNumber);
int main()
{
//Write an array of 10 students in the collage.
struct Student students[10];
int RollNumber;
getStudentsInfo(students);
//(a) write a program to print names of all students who joined in a particular year.
displaytStudentsInfo(students);
//(b) Write a program to print the data of a student whose roll number is given assignment
cout<<"Enter the Roll Number: ";
cin>>RollNumber;
displaytStudentsInfoOfGivenAssignment(students,RollNumber);
system("pause");
return 0;
}
void getStudentsInfo(struct Student students[]){
for(int i=0;i<10;i++){
struct Student student;
cout<<"Enter the Roll Number: ";
cin>>student.RollNumber;
cin.ignore();
cout<<"Enter the Name: ";
getline(cin,student.Name);
cout<<"Enter the Department: ";
getline(cin,student.Department);
cout<<"Enter the Course: ";
getline(cin,student.Course);
cout<<"Enter the Year: ";
cin>>student.Year;
students[i]=student;
cout<<"\n";
}
}
void displaytStudentsInfo(struct Student students[]){
cout << setw(15)<< left<<"Roll Number"<< left<< setw(15) << "Name"<<left<< setw(15)<<"Department"<<left<< setw(15)<<"Course"<<left<< setw(15)<<"Year"<<endl;
for(int i=0;i<10;i++){
cout << setw(15)<< left<<students[i].RollNumber<< left<< setw(15) << students[i].Name<<left<< setw(15)<<students[i].Department<<left<< setw(15)<<students[i].Course<<left<< setw(15)<<students[i].Year<<endl;
}
}
void displaytStudentsInfoOfGivenAssignment(struct Student students[],int rollNumber){
int isFound=0;
cout << setw(15)<< left<<"Roll Number"<< left<< setw(15) << "Name"<<left<< setw(15)<<"Department"<<left<< setw(15)<<"Course"<<left<< setw(15)<<"Year"<<endl;
for(int i=0;i<10;i++){
if(rollNumber==students[i].RollNumber){
cout << setw(15)<< left<<students[i].RollNumber<< left<< setw(15) << students[i].Name<<left<< setw(15)<<students[i].Department<<left<< setw(15)<<students[i].Course<<left<< setw(15)<<students[i].Year<<endl;
isFound++;
}
}
if(isFound==0){
cout<<"\nThe student with the roll number "<<rollNumber<<" does not exist.\n\n";
}
}
Comments
Leave a comment