Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

C++ Coding

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C++ Coding

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

//Acumulation Program

//Display name

#include<iostream>

using namespace std;

main()

cout<<"My name Sreyasi";

#include<iostream>

using namespace std;

main()

{ int x,y;

cout<<"Enter two numbers:";

cin>>x>>y;

int s=x+y;

cout<<"Sum="<<s<<endl;

return 0;

#include<iostream>

using namespace std;

main()

float c,f;

cout<<"Enter the Temperature in Celsius:";

cin>>c;

f=(9.0/5.0)*c+32.0;

cout<<"The Temperature in Celsius:"<<c<<endl;


cout<<"The Temperature in Fahrenheit:"<<f<<endl;

return 0;

#include<iostream>

using namespace std;

main()

int a,b;

cout<<"Enter any two numbers:";

cin>>a>>b;

if(a>b)

cout<<"Greater number is "<<a;

else

cout<<"Greater number is "<<b;

return 0;

#include<iostream>

using namespace std;

main()

int a,b,c;
cout<<"Enter any three numbers:";

cin>>a>>b>>c;

if(a>b && a>c)

cout<<"Greater number is "<<a;

else if(b>c)

cout<<"Greater number is "<<b;

else

cout<<"Greater number is "<<c;

return 0;

//find greater of two numbers

#include<iostream>

Using namespace std;

main()

int a,b,c=0;

cout<<"enter the integer";

cin>>a>>b;

if(a>b)

{
Cout<<a;

else

cout<<b;

Inheritance

//SINGLE INHERITANCE

#include<iostream>

using namespace std;

class A

public:

int a;

void getA()

cout<<"Enter value of A: ";

cin>>a;

};

class B : public A

public:

int b,c;

void getB()

{
cout<<"Enter value of B: ";

cin>>b;

void sum()

c=a+b;

cout<<"Sum= "<<c;

};

main()

B b1;

b1.getA();

b1.getB();

b1.sum();

//MULTILEVEL INHERITANCE

#include<iostream>

using namespace std;

class A

public:

int a;

void getA()

cout<<"Enter value of A: ";

cin>>a;
}

};

class B : public A

public:

int b;

void getB()

cout<<"Enter value of B: ";

cin>>b;

};

class C : public B

public:

int c;

void sum()

c=a+b;

cout<<"Sum= "<<c;

};

main()

C c1;

c1.getA();

c1.getB();
c1.sum();

//HIERARCHICHAL INHERITANCE

#include<iostream>

using namespace std;

class A

public:

int a;

void getA()

cout<<"Enter value of A: ";

cin>>a;

};

class B : public A

public:

int b,s;

void getB()

cout<<"Enter value of B: ";

cin>>b;

public:
void sum()

s=a+b;

cout<<"Sum= "<<s<<endl;

};

class C : public A

public:

int c,s;

void getC()

cout<<"Enter value of C: ";

cin>>c;

void sub()

s=a-c;

cout<<"Sub= "<<s;

};

main()

B b1;

b1.getA();

b1.getB();

b1.sum();
C c1;

c1.getA();

c1.getC();

c1.sub();

//Multiple inheritance

#include<iostream>

using namespace std;

class A

public:

int a;

void getA()

cout<<"Enter value of A: ";

cin>>a;

};

class B : public A

public:

int b;

void getB()

cout<<"Enter value of B: ";

cin>>b;

}
void multi()

int m=a*b;

cout<<"Multi="<<m<<endl;

};

class C : public A

public:

int c;

void getC()

cout<<"Enter value of C: ";

cin>>c;

void sum()

int s=a+c;

cout<<"Sum= "<<s;

};

main()

B b1;

b1.getA();

b1.getB();

b1.multi();
C c1;

c1.getA();

c1.getC();

c1.sum();

//Hybrid Inheritance

#include<iostream>

using namespace std;

class A

public:

int a;

void getA()

cout<<"Enter value of A: ";

cin>>a;

};

class B : public A

public:

int b,s;

void getB()

cout<<"Enter value of B: ";

cin>>b;
}

public:

void sum()

s=a+b;

cout<<"Sum= "<<s<<endl;

};

class C : public A

public:

int c;

void getC()

cout<<"Enter value of C: ";

cin>>c;

};

class D: public C

public:

int p;

void multi()

p=a*c;

cout<<"Multi= "<<p;
}

};

main()

B b1;

b1.getA();

b1.getB();

b1.sum();

D d1;

d1.getA();

d1.getC();

d1.multi();

Inheritance with Constructor

#include<iostream>

using namespace std;

class parent

protected:

int a,c;

public:

parent()

cout<<"\n I am parent";

parent(int x,int y)
{

c=x+y;

cout<<"\n\n Result:"<<c;

};

class child:public parent

private:

int m;

public:

child()

cout<<"\n I am child";

child(int p, int q)

m=p*q;

cout<<"\n\n product="<<m;

};

main()

child ch1;

child ch2(4,5);

}
Advanced Prog.

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop
*/

int main(int argc, char** argv) {

return 0;

You might also like