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

Popular posts from this blog

153: Write a program to read an amount (integer value) and break the amount into smallest possible number of bank notes. Note: The possible banknotes are 500, 100, 50, 20, 10, 5, 2, and 1

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345