202: Student Record: Create a struct to represent a student with attributes like name, roll number, and marks in different subjects. Write a program to input details of multiple students and display their information.
// Student Record: Create a struct to represent a student with attributes like name, roll number, and marks in different subjects.
// Write a program to input details of multiple students and display their information.
#include <iostream>
using namespace std;
struct Student
{
string name, roll_num;
int bio_marks, phy_marks, comp_marks;
};
Student New_Student();
template <typename T>
T input(string x);
string input_string(string x);
void show_student_data(Student x);
int main()
{
Student s1 = New_Student();
Student s2 = New_Student();
Student s3 = New_Student();
system("cls");
show_student_data(s1);
cout << endl;
show_student_data(s2);
cout << endl;
show_student_data(s3);
cout << endl;
return 0;
}
Student New_Student()
{
system("cls");
Student x;
x.name = input_string("Enter name: ");
x.roll_num = input<string>("Enter roll no: ");
x.bio_marks = input<int>("Enter bio marks: ");
x.comp_marks = input<int>("Enter computer marks: ");
x.phy_marks = input<int>("Enter physics marks: ");
return x;
}
void show_student_data(Student x)
{
cout << "Name: " << x.name << endl;
cout << "Roll no: " << x.roll_num << endl;
cout << "Biology marks: " << x.bio_marks << endl;
cout << "Physics marks: " << x.phy_marks << endl;
cout << "Computer marks: " << x.comp_marks << endl;
}
template <typename T>
T input(string x)
{
T y;
cout << x;
cin >> y;
return y;
}
string input_string(string x)
{
string y;
cout << x;
cin >> y;
return y;
}
Comments
Post a Comment