Answer to Question #202734 in C++ for Laiba Kanwal

Question #202734

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.


1
Expert's answer
2021-06-03T13:41:59-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog