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.
#include <iostream>
#include <string>
using namespace std;
struct Students
{
int roll{ 0 };
string name;
string departament;
int course{ 0 };
int year{ 0 };
};
void setStudent(Students *p, int n, int num)
{
string line;
cout << "Enter student data number " << num << endl;
num = num - 1;
cout << "Enter roll number student:";
cin >> p[num].roll;
cin.get();
cout << "Enter name student:";
getline(cin, line);
p[num].name = line;
cout << "Enter the student department:";
getline(cin, line);
p[num].departament = line;
cout << "Enter the student's course of study:";
cin >> p[num].course;
cout << "Enter the year the student entered:";
cin>> p[num].year;
}
void viewStudent(Students* p, int n, int num)
{
cout << " Student data number " << num << endl;
num = num - 1;
cout << "Roll number: " << p[num].roll<<endl;
cout << "Name: " << p[num].name<<endl;
cout << "Departament: " << p[num].departament<<endl;
cout << "Course: " << p[num].course<<endl;
cout << "Year: " << p[num].year<<endl;
}
int main()
{
Students group[10];
//enter dataset all students
for (int i = 1; i < 11; i++)
{
setStudent(group, 10, i);
}
// output names of all students who joined in a particular year.
int year_choise;
cout << "Enter the year of receipt: ";
cin >> year_choise;
for (int i = 0; i < 10; i++)
{
cout << "displaying the names of students who joined in ." << year_choise << "years:" << endl;
if (group[i].year == year_choise)
{
cout << group[i].name<<endl;
}
}
// data of the student whose roll number is entered
int roll_choise;
cin >> roll_choise;
for (int i = 0; i < 10; i++)
{
if (group[i].roll == roll_choise)
{
viewStudent(group, 4, i + 1);
}
}
return 0;
}
Comments
Leave a comment