Posted by MindBreaker at 2:28 PM
Read our previous post
Create a
structure called markssheet having variables:
RollNo,
StsName[50], Urdu, Eng, Math, Percentage and grade.
Calculate
percentage and grade using functions inside structures. Write a program that
takes this information in an array
for a number
of students and displays result in a decent manner.
Source code
#include <iostream>
#include <fstream>
using namespace std;
struct
marksheet
{
//int Urdu;int
Eng;int Math;
int
RollNo(int &Roll_No)
{
int
roll;
roll = Roll_No;
return
roll;
}
string Name(string StudentName)
{
string NewName;
NewName = StudentName;
return
NewName;
}
float
percentage(int Urdu,int
Eng,int Math)
{
float
result; int total = 300;
result = Math + Urdu + Eng;
result = (result / total) * 100;
return
result;
}
void
grade(int Urdu,int
Eng,int Math)
{
//Maths
cout << endl;
cout << "Math Grade: " ;
if(Math
== 0 && Math <= 49)
{
cout <<'F'<< endl ;
}
else
if(Math >= 50 && Math <= 60)
{
cout <<'D'<< endl;
}
else
if(Math >= 61 && Math <= 70)
{
cout <<'C'<< endl;
}
else
if(Math >= 71 && Math <= 80)
{
cout <<'B'<< endl;
}
else
if(Math >= 81 && Math <= 100)
{
cout <<'A'<< endl;
}
else
if(Math >100)
{
cout << "invalid input" << endl;
}
else
if(Math < 0)
{
cout << "invalid input" << endl;
}
//English
cout << endl;
cout << "English Grade: " ;
if(Eng
== 0 && Eng <= 49)
{
cout <<'F' << endl;
}
else
if(Eng >= 50 && Eng <= 60)
{
cout <<'D'<< endl;
}
else
if(Eng >= 61 && Eng <= 70)
{
cout <<'C'<< endl;
}
else
if(Eng >= 71 && Eng <= 80)
{
cout <<'B'<< endl;
}
else
if(Eng >= 81 && Eng <= 100)
{
cout <<'A'<< endl;
}
else
if(Eng >100)
{
cout << "invalid input" << endl;
}
else
if(Eng < 0)
{
cout << "invalid input" << endl;
}
//Urdu
cout << endl;
cout << "Urdu Grade: "<< endl ;
if(Urdu
== 0 && Urdu <= 49)
{
cout <<'F'<< endl;
}
else
if(Urdu >= 50 && Urdu <= 60)
{
cout <<'D'<< endl;
}
else
if(Urdu >= 61 && Urdu <= 70)
{
cout <<'C'<< endl;
}
else
if(Urdu >= 71 && Urdu <= 80)
{
cout <<'B'<< endl;
}
else
if(Urdu >= 81 && Urdu<= 100)
{
cout << "A" << endl;
}
else
if(Urdu >100)
{
cout << "invalid input" << endl;
}
else
if(Urdu < 0)
{
cout << "invalid input" << endl;
}
}
};
void
main()
{
marksheet m, m1,m2,m3;
cout << "Enter
student's RollNo: ";
int roll;
cin >> roll;
cout << endl;
cout << "Enter
Student Name: ";
string Name;
cin >> Name;
cout << endl;
cout << "**Enter
marks**" << endl;
cout << "Marks
of Urdu: "; int urdu; cin >>
urdu;
cout << endl;
cout << "Marks
of Eng: "; int eng; cin >>
eng;
cout << endl;
cout << "Marks
of Math: "; int math; cin >>
math;
cout << endl << endl <<
endl;
cout << "Roll
Number: " << m.RollNo(roll) << endl;
cout << "Student
Name: " << m.Name(Name) << endl;
m.grade(urdu, eng, math);
cout << "Percentage:
" << m.percentage(urdu, eng, math) << endl;
}
Output
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.