Write a program of student mark sheet where Physics, Chemistry and Maths are the subject as input

Write a program of student mark sheet where Physics, Chemistry and Maths are the subject as input

 

Assignment
5

Write a program of student mark sheet where Physics,
Chemistry and Maths are the subject as input.

We can
solve this problem using two ways, explain as below-

Option 1: Accept
only one student.

Program
Code with explanation:

1.   
#include
<iostream>

2.   
using
namespace std;

3.   
int
main()

4.   
{

5.   
            int
srno, phy, chem, math;

6.   
            char
sname[100];

7.   
            cout<<“Accept
the Roll Number of Student \n”;

8.   
            cin>>srno;

9.   
            cout<<“Accept
the name of Student \n”;

10.             cin>>sname;

11.             cout<<“Accept
the Marks \n”;

12.             cout<<“Accept
the Marks of Physics \n”;

13.             cin>>phy;

14.             cout<<“Accept
the Marks of Chemistry \n”;  

15.             cin>>chem;

16.             cout<<“Accept
the Marks of Maths \n”;  

17.             cin>>math;

18.             cout<<“Display
Mark Sheet of student \n\n”;

19.             cout<<“Roll
Number \t Name \t\t Physics \t\t Chemistry \t Maths \n”;

20.             cout<<srno<<“\t\t”<<sname<<“\t\t”<<phy<<“\t\t”;

21.             cout<<chem<<“\t\t”<<math;

22.             return
0;

23. }

Explanation
of Code:

Line
No. 1 and 2: include the Library file and stander input – output functions.

Line
No. 3: main function header.

Line
No. 4 and 23: Begin and end of main function respectively.

Line
No. 5: Declare the variables srno, phy, chem, math as integer.

Line
No. 6: Declare the array variable sname to store the name of student.

Line No. 7 to 17: Accept Roll Number,
Name and Mark of three subjects. 

Line No. 18 to 21: Display mark sheet
of Student using accepted information.

Line No. 22: return statement
appropriate with main function return data type.

Program
Code for run:

#include
<iostream>

using
namespace std;

int
main()

{

            int
srno, phy, chem, math;

            char
sname[100];

            float
per;

            cout<<“Accept
the Roll Number of Student \n”;

            cin>>srno;

            cout<<“Accept
the name of Student \n”;

            cin>>sname;

            cout<<“Accept
the Marks \n”;

            cout<<“Accept
the Marks of Physics \n”;

            cin>>phy;

            cout<<“Accept
the Marks of Chemistry \n”;  

            cin>>chem;

            cout<<“Accept
the Marks of Maths \n”;  

            cin>>math;

            cout<<“Display
Mark Sheet of student \n\n”;

            cout<<“Roll
Number \t Name \t\t Physics \t\t Chemistry \t Maths\n”;

            cout<<srno<<“\t\t”<<sname<<“\t\t”<<phy<<“\t\t”<<chem<<“\t\t”<<math;

            return
0;

}

Output
of Program:

Accept
the Roll Number of Student

1

Accept
the name of Student

ABCD

Accept
the Marks

Accept
the Marks of Physics

87

Accept
the Marks of Chemistry

88

Accept
the Marks of Maths

89  98

Display
Mark Sheet of student

 

Roll
Number    Name             Physics           Chemistry        Maths

1                      ABCD             87                    88                    98

 

Option 2: Accept
number of student using for loop.

Program
Code with explanation:

1.   
#include
<iostream>

2.   
using
namespace std;

3.   
int
main()

4.   
{

5.   
      int
srno[10],phy[10],chem[10],math[10],n,i;

6.   
      char
sname[10][100];

7.   
      cout<<“How
Many Students Record Accepted\n”;

8.   
      cin>>n;

9.   
      for(i
= 0; i < n ; i++)

10.       {

11.                   cout<<“Accept
the Roll Number of Student \n”;

12.                   cin>>srno[i];

13.                   cout<<“Accept
the name of Student \n”;

14.                   cin>>sname[i];

15.                   cout<<“Accept
the Marks \n”;

16.                   cout<<“Accept
the Marks of Physics \n”;

17.                   cin>>phy[i];

18.                   cout<<“Accept
the Marks of Chemistry \n”;  

19.                   cin>>chem[i];

20.                   cout<<“Accept
the Marks of Maths \n”;  

21.                   cin>>math[i];

22.       }

23.       cout<<“\tDisplay
Mark Sheet of students \n”;

24.       cout<<“***********************************************************************\n”;

25.       cout<<“Roll
Number\tName\t\tPhysics\t\tChemistry\tMaths\n”;

26.       for(i=0; i < n; i++)

27.       {

28.                   cout<<srno[i]<<“\t\t”<<sname[i]<<“\t\t”<<phy[i]<<“\t\t”<<chem[i];

29.                   cout<<“\t\t”<<math[i]<<“\n”;

30.       }

31.       return
0;

32. }

Explanation
of Code:

Line
No. 1 and 2: include the Library file and stander input – output functions.

Line
No. 3: main function header.

Line
No. 4 and 32: Begin and end of main function respectively.

Line
No. 5: Declare the variables srno, phy, chem, math as integer.

Line
No. 6: Declare the array variable sname to store the name of student.

Line No. 7 and 8: Accept integer for
how many student records to accept.

Line No. 9 to 22: Accept Roll Number,
Name and Mark of three subjects for ‘n’ students using for loop. For loop move ‘n’
time.  

Line No. 23, 24 and
25:
Display
the massage. 

Line No. 26 to 30: Display mark sheet
of ‘n’ students using accepted information. For loop move ‘n’ time.

Line No. 31: return statement
appropriate with main function return data type.

Program
Code for run:

#include
<iostream>

using
namespace std;

int
main()

{

            int
srno[10],phy[10],chem[10],math[10],n,i;

            char
sname[10][100];

            cout<<“How
Many Students Record Accepted\n”;

            cin>>n;

            for(i=0;i<n;i++)

            {

                cout<<“Accept the Roll Number of
Student \n”;

                cin>>srno[i];

                cout<<“Accept the name of
Student \n”;

                cin>>sname[i];

                cout<<“Accept the Marks
\n”;

                cout<<“Accept the Marks of
Physics \n”;

                cin>>phy[i];

                cout<<“Accept the Marks of
Chemistry \n”;  

                cin>>chem[i];

                cout<<“Accept the Marks of Maths
\n”;  

                cin>>math[i];

            }

            cout<<“\tDisplay
Mark Sheet of students \n”;

            cout<<“***********************************************************************\n”;

            cout<<“Roll
Number\tName\t\tPhysics\t\tChemistry\tMaths\n”;

            for(i=0;i<n;i++)

{

                        cout<<srno[i]<<“\t\t”<<sname[i]<<“\t\t”<<phy[i]<<“\t\t”<<chem[i];

cout<<“\t\t”<<math[i]<<“\n”;

}

        return 0;

}

 

Output
of Program:

How
Many Students Record Accepted

2

Accept
the Roll Number of Student

1

Accept
the name of Student

AAA

Accept
the Marks

Accept
the Marks of Physics

89

Accept
the Marks of Chemistry

89

Accept
the Marks of Maths

89

Accept
the Roll Number of Student

2

Accept
the name of Student

BBB

Accept
the Marks

Accept
the Marks of Physics

99

Accept
the Marks of Chemistry

99

Accept
the Marks of Maths

99

            Display Mark Sheet of students

***********************************************************************

Roll
Number    Name             Physics           Chemistry        Maths

1                      AAA                89                    89                    89

2                      BBB                99                    99                    99

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top