Professional Documents
Culture Documents
Object Oriented Programming
Object Oriented Programming
Q1) Write a cpp program for finding total & avg for single students. (Note:
create class & declare variable s1, s2, s3, s4, s5, total, average;
void display( )
void getdata(75,85,96,75,88);
SOURCE CODE:
#include<iostream>
class Student{
int s1,s2,s3,s4,s5,tot;
float avg;
public:
s1=m1;
s2=m2;
s3=m3;
s4=m4;
s5=m5;
void display(){
tot=s1+s2+s3+s4+s5;
avg=tot/5.0;
};
int main(){
Student s;
s.getdata(36,37,96,95,18);
s.display();
return 0;
OUTPUT:
Q2) Develop a CPP program for static data member
(Note:
void func1();
a++;
then create three object c1,c2,c3 & call this func1 using that objects.
SOURCE CODE:
#include <iostream>
class MyClass {
public:
static int a;
void func1() {
a++;
};
int MyClass::a = 0;
int main() {
c1.func1();
c2.func1();
c3.func1();
return 0;
OUTPUT:
Q3) Develop a CPP program for static data member & member function
(Note:
a++;
SOURCE CODE:
#include <iostream>
class MyClass {
public:
static int a;
};
int MyClass::a = 0;
int main() {
MyClass::func1();
return 0;
OUTPUT: