//student.h
class student
{
private :
int studentno;
char name[20];
int year;
int semester;
int marks[5];
char grade[5];
double avgmarks;
public :
student(int pstudentno,int psemester,char pname[],int pyear);
void inputmarks();
void findgrades();
void calavgmarks();
void displaystudentdetails();
};
//student.cpp
#include "student.h"
#include <cstring>
#include <iostream>
using namespace std;
student::student(int pstudentno,int psemester,char pname[],int pyear)
{
studentno=pstudentno;
semester=psemester;
strcpy(name,pname);
year=pyear;
}
void student::inputmarks()
{
for(int i=0;i<5;i++)
{
cout<<"Enter mark "<<i+1<<" ";
cin>>marks[i];
}
}
void student::findgrades()
{
for(int i=0;i<5;i++)
{
if(marks[i]>=75 && marks[i]<=100)
{
grade[i]='A';
}
else if(marks[i]<75 && marks[i]>=60)
{
grade[i]='B';
}
else if(marks[i]<60 && marks[i]>=45)
{
grade[i]='S';
}
else if(marks[i]<45)
{
grade[i]='F';
}
}
}
void student::calavgmarks()
{ float sum=0;
for(int i=0;i<5;i++)
{
sum=sum+marks[i];
}
avgmarks=sum/5.0;
}
void student::displaystudentdetails()
{
cout<<"student no : "<<studentno<<endl;
cout<<"student name : "<<name<<endl;
cout<<"year : "<<year<<endl;
cout<<"semester : "<<semester<<endl;
cout<<"\t"<<"module1 "<<"module2 "<<"module3 "<<"module4 "<<"module5"<<endl;
cout<<"marks "<<marks[0]<<"\t "<<marks[1]<<"\t "<<marks[2]<<"\t "<<marks[3]<<"\t "<<marks[4]<<endl;
cout<<"Grade "<<grade[0]<<"\t "<<grade[1]<<"\t "<<grade[2]<<"\t "<<grade[3]<<"\t "<<grade[4]<<endl;
cout<<"Average marks = "<<avgmarks<<endl;
}
//paperlb_3.cpp
#include <cstring>
#include <iostream>
using namespace std;
student::student(int pstudentno,int psemester,char pname[],int pyear)
{
studentno=pstudentno;
semester=psemester;
strcpy(name,pname);
year=pyear;
}
void student::inputmarks()
{
for(int i=0;i<5;i++)
{
cout<<"Enter mark "<<i+1<<" ";
cin>>marks[i];
}
}
void student::findgrades()
{
for(int i=0;i<5;i++)
{
if(marks[i]>=75 && marks[i]<=100)
{
grade[i]='A';
}
else if(marks[i]<75 && marks[i]>=60)
{
grade[i]='B';
}
else if(marks[i]<60 && marks[i]>=45)
{
grade[i]='S';
}
else if(marks[i]<45)
{
grade[i]='F';
}
}
}
void student::calavgmarks()
{ float sum=0;
for(int i=0;i<5;i++)
{
sum=sum+marks[i];
}
avgmarks=sum/5.0;
}
void student::displaystudentdetails()
{
cout<<"student no : "<<studentno<<endl;
cout<<"student name : "<<name<<endl;
cout<<"year : "<<year<<endl;
cout<<"semester : "<<semester<<endl;
cout<<"\t"<<"module1 "<<"module2 "<<"module3 "<<"module4 "<<"module5"<<endl;
cout<<"marks "<<marks[0]<<"\t "<<marks[1]<<"\t "<<marks[2]<<"\t "<<marks[3]<<"\t "<<marks[4]<<endl;
cout<<"Grade "<<grade[0]<<"\t "<<grade[1]<<"\t "<<grade[2]<<"\t "<<grade[3]<<"\t "<<grade[4]<<endl;
cout<<"Average marks = "<<avgmarks<<endl;
}
//paperlb_3.cpp
#include "student.h"
#include <iostream>
using namespace std;
int main()
{
student s1(10,1,"Saman",1);
s1.inputmarks();
s1.findgrades();
s1.calavgmarks();
s1.displaystudentdetails();
return 0;
}
using namespace std;
int main()
{
student s1(10,1,"Saman",1);
s1.inputmarks();
s1.findgrades();
s1.calavgmarks();
s1.displaystudentdetails();
return 0;
}
0 comments:
Post a Comment