Write a C++ program to define a structure with 5 members. The first member be student name and the other four members be student marks obtained in four subjects. Input values from the user. Add marks of the subjects and calculate the total marks and then print these individual subject marks as well as total marks of the student.
#include <iostream>
using namespace std;
struct Student
{
string name;
int marks1;
int marks2;
int marks3;
int marks4;
};
int main()
{
struct Student s1;
cout<<"\nEnter the name of the student: ";
cin>>s1.name;
cout<<"\nEnter marks of subject 1: ";
cin>>s1.marks1;
cout<<"\nEnter marks of subject 2: ";
cin>>s1.marks2;
cout<<"\nEnter marks of subject 3: ";
cin>>s1.marks3;
cout<<"\nEnter marks of subject 4: ";
cin>>s1.marks4;
int totalMarks=s1.marks1+s1.marks2+s1.marks3+s1.marks4;
cout<<"\nIndividual marks for "<<s1.name<<" are: \n";
cout<<"Subject 1: "<<s1.marks1<<endl;
cout<<"Subject 1: "<<s1.marks2<<endl;
cout<<"Subject 1: "<<s1.marks3<<endl;
cout<<"Subject 1: "<<s1.marks4<<endl;
cout<<"Total Mask is: "<<totalMarks;
return 0;
}
Comments
Leave a comment