Tuesday, 8 October 2024

Journal PRogram 4

 /*

Def : WAP to build a class Student,which accept student number,

  name and marks of 3 subjects.Calculate total and

  percentage using different member fuction and display

  all information.

Tut Date:

Lab Date:

*/

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

class Student

{

int rno,m1,m2,m3,total;

float per;

char name[20];

public :

void getData()

{

cout<<"\n Enter roll number : ";

cin>>rno;

cout<<"\n Enter student name : ";

flushall();

gets(name);

cout<<"\n Enter marks of subject1 : ";

cin>>m1;

cout<<"\n Enter marks of subject2 : ";

cin>>m2;

cout<<"\n Enter marks of subject3 : ";

cin>>m3;

}

void calculate();

void printData();

};

void Student::calculate()

{

total=m1+m2+m3;

per=total/3.0;

}

void Student::printData()

{

cout<<"\n\t\t STUDENT DETAILS ";

cout<<"\n======================================";

cout<<"\n Roll Number : "<<rno;

cout<<"\n Student Name : "<<name;

cout<<"\n Marks of Subject1 : "<<m1;

cout<<"\n Marks of Subject2 : "<<m2;

cout<<"\n Marks of Subject3 : "<<m3;

cout<<"\n Total Marks : "<<total;

cout.precision(2);

cout<<"\n Percentage : "<<per;

cout<<"\n======================================";

}

int main()

{

clrscr();

Student s;

s.getData();

s.calculate();

s.printData();

getch();

return 0;

}


No comments:

Post a Comment