Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

OBJECT ORIENTED PROGRAMMING LABORATORY

Ex. No 1 : Implementation of Static Data member, Default Argument


and Friend Function

Anjana S

20104014

AIM:

To Write a C++ program for Students mark analysis using Static Data
member, Default Argument and Friend Function.

ALGORITHM:

Step 1: Start the Program execution.

Step 2: Get the Students detail and calculate the Result analysis.

Step 3: Default value is assigned for pass in a function and the function is
assigned with default value when value for pass is not given in checking for
pass status.

Step 4: Declare the integer count as Static member each time when the
student is pass it will be incremented and finally specify pass count.

Step 5: The friend function display is used to access the private variables from
two classes and acting as the bridge between two classes.

Step 6: Stop the Program execution.

PROGRAM:

#include <iostream>

using namespace std;

int cp(int,int,int,int=50);
void printline(char ch='`',int rage =70);
class per;

class acc

int rno,tot;

static int count;

int m1,m2,m3;

char name[30],grade;

float avg;

public:

void getdata()

cout<<"Enter the id: ";

cin>>rno;

cout<<"Enter the name: ";

cin>>name;

cout<<"Enter mark1,mark2,mark3: ";

cin>>m1>>m2>>m3;

friend void display(acc,per);

void cal()

tot=0;
if(cp(m1,m2,m3))

{
cout<<"Result=pass"<<endl;

tot=m1+m2+m3;

avg=tot/3;

count=count+1;

if(avg>=90)

grade='O';

if(avg>=70 && avg<90)

grade='A';

if(avg>=50 && avg<70)

grade='B';

else

cout<<"Result=Fail"<<endl; }

static void showcount(void) {

cout<<endl;

cout<<"count:"<<count; }

};
int acc::count;
class per

char add[30];

long tel;

public:

void getdata1()

cout<<"Enter the address:";

cin>>add;

cout<<"Enter the phoneno:";

cin>>tel;

friend void display(acc a,per p)

cout<<endl;

cout<<"Name:"<<a.name<<endl;

cout<<"ID:"<<a.rno<<endl;

cout<<"Mark1: "<<a.m1<<"\tMark2: "<<a.m2<<"\tMark3:


"<<a.m3<<endl;

cout<<"Address:"<<p.add<<endl;

cout<<"Phone no: "<<p.tel<<endl;


if(cp(a.m1,a.m2,a.m3))

cout<<"Total:"<<a.m1<<endl;
cout<<"Average:"<<a.avg<<endl;

cout<<"Grade:"<<a.grade<<endl; }

};

int cp(int m1,int m2,int m3,int pass1)

if(m1>=pass1 && m2>=pass1 && m3>=pass1)

return(1);

else

return(0);

int main()

int i,n;

per p1[20];

acc a1[20];

cout<<"Enter the no of students:";

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

a1[i].getdata();
p1[i].getdata1();

a1[i].cal();

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

printline('-');

display(a1[i],p1[i]);

printline();

acc::showcount();

return 0;

void printline(char ch,int range) {

int i;

cout<<endl;

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

cout<<ch; }
OUTPUT:

RESULT:

Thus the program to perform Students mark analysis using Static Data
member, Default Argument and Friend Function was implemented.

You might also like