Monday, February 18, 2013

OOCP (CPP) : Example # 04 : Prepare Result of Students using C++ Classes and method

OOCP (CPP)  :  Example # 04 : Prepare Result of Students using C++ Classes and method

* Lets start learning CPP (C++) Using Example.

* Lets learn how to create class including 3 member functions to generate result of students.

//Written by Latest Technology Guide    
//Title : OOCP (CPP)  :  Example # 
04 : Prepare Result of Students using C++ Classes and method


#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

class student
{
private :
int no,mark1,mark2,total;
float per;
char name[10];

public :
void getdata();
void caldata();
void displaydata();
};

void student :: getdata()
{
clrscr();
cout << "Enter No :";
cin >> no;
cout << "Enter Name : ";
cin >> name;
cout << "Mark 1 : ";
cin >> mark1;
cout << "Mark 2 : ";
cin >> mark2;
}
void student :: caldata()
{
total = mark1 + mark2;
per = total/2.0;
}
void student :: displaydata()
{
cout << "No " << setw(15) << "Name" << setw(15) << "Total" << setw(15) << "Percentage" << endl;
cout << no << setw(15) << name << setw(15) << total << setw(15) << per << endl;
}

void main()
{
clrscr();
student obj;

obj.getdata();
obj.caldata();
obj.displaydata();

getch();
}

Output:
* you will find output as : Name  Total and Percentage

--------------------------------------------------------------------------------
OOCP (CPP)  :  Example # 04 : Prepare Result of Students using C++ Classes and method

* Example shows how to create class and methods in C++. Here we have created student class including getdata(), caldate() and displaydata() method.
* getdata() method is used to get value from user.
* caldata() method is used to calculate value of total and percentage.
* displaydata() method is used to display value to users.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment