Posts

Showing posts from October, 2016

Program to illustrate the order of execution of constructors and destructors in inheritance.

Image
#include<iostream> using namespace std; class Base {   public:   Base ( )   {     cout << "Inside Base constructor" << endl;   }   ~Base ( )   {     cout << "Inside Base destructor" << endl;   } }; class Derived : public Base {   public:     Derived  ( )   {     cout << "Inside Derived constructor" << endl;   }   ~Derived ( )   {     cout << "Inside Derived destructor" << endl;   } }; int main( ) {   Derived x;   x.~Derived();   cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to find the 2's complement of a binary number.

Image
#include<iostream> #include<string.h> using namespace std; int main() { char a[10],b[10],c; int i,count=0; cout<<"Enter the binary number : "; gets(a); strcpy(b,a); for(i=0;i<10;i++) { if(a[i]=='1') { a[i]='0'; count++; } else if(a[i]=='0') { a[i]='1'; count++; } } i=count-1; c='1'; do { if(a[i]=='1') { a[i]='0'; c='1'; } else if(a[i]=='0') { a[i]='1'; c='0'; } i--; }while(c=='1'); cout<<"The 2's Compliment of "<<b; cout<<" is:"<<a<<endl; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; return 0; } Output:

Program to illustrate the concept of ambiguity in multiple inheritance. (a) with ambiguity. (b)without ambiguity

Image
(a) With Ambiguity: #include<iostream> using namespace std; class A { public: void show() { cout<<"Class A"<<endl; } }; class B { public: void show() { cout<<"Class B"<<endl; } }; class C:public A,public B//multiple inheritance { public: int a; }; int main() { C a; a.show();//causes inheritance cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output (a): (b) Without Ambiguity: #include<iostream> using namespace std; class A { public: void show() { cout<<"Class A"<<endl; } }; class B { public: void show() { cout<<"Class B"<<endl; } }; class C:public A,public B//multiple inheritance { public: int ab; }; int main() { C a; a.A::show(); a.B::show(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Out...

Program to illustrate the concept of multilevel inheritance.

Image
#include<iostream> using namespace std; class A { public:  int a=1; }; class B:public A { public: int b=2; }; class C:public B//multilevel inhertance { public: C(){ cout<<a<<endl<<b<<endl; } }; int main() { C a; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of inheritance

Image
#include<iostream> using namespace std; class A { public:  int a=1; }; class B:public A//single inheritance { public: B(){ cout<<a<<endl; } }; int main() { B a; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of destructors.

Image
#include<iostream> using namespace std; class A { private: int a=1; public: A()//constructor {   a++; cout<<"Constructor "<<a<<endl; } ~A()//destructor {   --a; cout<<"Destructor "<<a<<endl; } }; int main() { A a; a.~A(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of copy constructor.

Image
#include<iostream> using namespace std; class A { private: int a; public: A()//Default Constructor {   a=1; } A(A &c)//copy Constructor { a=c.a; } void show(){ cout<<"a = "<<a<<endl; } }; int main() { A a; a.show(); A b(a); b.show(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of parameterized constructor.

Image
#include<iostream> using namespace std; class A { private: int a,b; public: A()//Default Constructor {   a=b=1; } A(int x)//Parameterized Constructor { a=b=x; } void show(){ cout<<"a = "<<a<<endl<<"b = "<<b<<endl; } }; int main() { A a; a.show(); A b(20); b.show(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of default constructor

Image
#include<iostream> using namespace std; class A { public: A() { cout<<"Default Constructor"<<endl; } }; int main() { A a; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to find sum of two numbers using function.

Image
#include<iostream> using namespace std; int sum(int,int);//functionjdeclaration int main() { cout<<"Sum is "<<sum(4,5)<<endl;//function calling cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } //function defination int sum(int x,int y){ return x+y; } Output:

Program to show the working of static members in a class.

Image
#include<iostream> using namespace std; class A{ private: static int count; public: void read(){ count++; } void show(){ cout<<"Count : "<<count<<endl; } }; int A::count; int main() { A b,c; b.show(); c.show(); b.read(); c.read(); cout<<"\nAfter reading data"<<endl; b.show(); c.show(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to show the working of static members in a class.

Image
#include<iostream> using namespace std; class A{ private: static int count; public: void read(){ count++; } void show(){ cout<<"Count : "<<count<<endl; } }; int A::count; int main() { A b,c; b.show(); c.show(); b.read(); c.read(); cout<<"\nAfter reading data"<<endl; b.show(); c.show(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

A program that read any line of text & display number of upper case, lower case, digit, space& other character

Image
#include<iostream> using namespace std; int main() { int up=0,lo=0,di=0,space=0,other=0,i=0; char text[100]; cout<<"Enter text :"; cin.getline(text,100); while(text[i]!=0) { int c=int(text[i]); if (c>=65 && c<=90) up++; else if(c>=97 &&c<=122) lo++; else if(c>=48 &&c<=57) di++; else if(text[i]==' ') space++; else other++; ++i; } cout<<"\n\nResult:\n"; cout<<"Uppercase"<<up<<endl; cout<<"Lowercase"<<lo<<endl; cout<<"Digit"<<di<<endl; cout<<"Spaces"<<space<<endl; cout<<"Other"<<other<<endl; cout<<"\n\n"; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to illustrate the concept of classes and object.

Image
#include<iostream> using namespace std; class student{ private: int rollnum,age; char name[60]; public: void getstd(){ cout<<"Enter the Name"<<endl; cin>>name; cout<<"Enter the Age"<<endl; cin>>age; cout<<"Enter the Roll Number"<<endl; cin>>rollnum; } void showstd(){ cout<<"Name is "<<name<<endl<<"Age is "<<age<<endl<<"Roll Number is"<<rollnum<<endl; } }; int main() { student s1; cout<<"Enter Value of Students\n"; s1.getstd(); cout<<"Output\n"; s1.showstd(); cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Write a program that will read the value of x and evaluate the following function: Y= 2 for x>0, Y=0 for x=0 Use nested statements with the conditional control statement.

Image
#include<iostream> using namespace std; int main() { int x; cout<<"Enter x\n"; cin>>x; if(x>0) { cout<<"x is "<<x<<" Y is 2\n\n"<<endl; } else if(x==0) { cout<<"x is "<<x<<" Y is 0\n\n"<<endl; } else { cout<<"x is negative So is Y\n\n"<<endl; } cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to reverse an integer number.

Image
#include<iostream> using namespace std; int main() { int n,num,digit,rev=0; cout<<"Enter a positive number:"; cin>>num; n=num; do{ digit=num%10; rev=(rev*10)+digit; num=num/10; } while (num!=0); cout<<"The reverse of the number is :"<<rev<<endl; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to display the different colors using the switch statement.

Image
#include<iostream> using namespace std; int main() { int a; cout<<"Enter the value to display the colour\n\n1.Red\n2.Blue\n3.Green\n4.White\n5.Black"<<endl; cout<<"Enter Your Choice:"; cin>>a; switch(a) { case 1: cout<<"Colour is Red\n"; break; case 2: cout<<"Colour is Blue\n"; break; case 3: cout<<"Colour is Green\n"; break; case 4: cout<<"Colour is White\n"; break; case 5: cout<<"Colour is Black\n"; break; default: cout<<"No Result\n"; } cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to find all roots of quadratic equations.

Image
#include<iostream> #include<math.h> using namespace std; int main() { float a,b,c,d,e; cout<<"Enter the values of a,b,c"<<endl; cin>>a>>b>>c; d=(sqrt(pow(b,2)-(4*a*c))); float f=(-b+d)/(2*a); float g=(-b-d)/(2*a); cout<<"for - "<<g<<endl<<"for + "<<f<<endl; e=pow(b,2)-(4*a*c); if (e>0) cout<<"real and unequal\n\n"; else if(e<0) cout<<"imaginary\n\n"; else cout<<"real and equal\n\n"; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program To Check Whether a Number is a Armstrong or not.

Image
#include<iostream> using namespace std; int main() { int n,n1,rem,num=0; cout<<"Enter a positive number:"; cin>>n; n1=n; while (n1!=0){ rem=n1%10; num+=rem*rem*rem; n1=n1/10; } if(num==n) cout<<"The number is armstrong\n\n"; else cout<<"The number is not a armstrong\n\n"; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program To Check Whether a Number is a Palindrome or not.

Image
#include<iostream> using namespace std; int main() { int n,num,digit,rev=0; cout<<"Enter a positive number:"; cin>>num; n=num; do{ digit=num%10; rev=(rev*10)+digit; num=num/10; } while (num!=0); cout<<"The reverse of the number is :"<<rev<<endl; if(n==rev) cout<<"The number is palindrome\n\n"; else cout<<"The number is not a palindrome\n\n"; cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } Output:

Program to interchange the values of two numbers: (a)w/o 3rd variable (b)with 3rd variable

Image
a.Without 3rd Variable #include<iostream> using namespace std; int main() {    int a,b;    cout<<"Enter the value of a\n";    cin>>a;    cout<<"Enter the value of b\n";    cin>>b;    cout<<"value of a and b before swap is :\nA = "<<a<<endl<<"B = "<<b<<endl;    b=a+b;    a=b-a;    b=b-a;    cout<<"value of a and b after swap is :\nA = "<<a<<endl<<"B = "<<b<<endl;    cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; } b.With 3rd Variable #include<iostream> using namespace std; int main() {    int a,b,temp;    cout<<"Enter the value of a\n";    cin>>a;    cout<<"Enter the value of b\n";    cin>>b;    cout<<"val...

Program to find the area and circumference of the circle

Image
#include<iostream> #include<math.h> #define PI 3.14 using namespace std; int main() {     float area,circum,r;     cout<<"Enter the radius\n";     cin>>r;     area=PI*pow(r,2.0);         cout<<"The area Of the circle is:"<<area<<endl;     circum=2*PI*r;         cout<<"The circumfrence Of the circle is:"<<circum<<endl;         cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/"; return 0; } Output:

Example of Synopsis in LaTeX

Include the following source Code in Document Environment in your LaTeX File. It is an example of writing Synopsis of a particular project,You can change content according to your needs!! Source Code: \documentclass[12pt]{article} \usepackage{graphicx} \usepackage{wrapfig} \usepackage{multicol} \usepackage{caption} \usepackage{subcaption} \usepackage{transparent} \usepackage{multirow} \usepackage{eso-pic} \usepackage[utf8]{inputenc} \usepackage{color} \setcounter{secnumdepth}{5} \usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \rhead{Project S-r} \lhead{OOP's with C++} \rfoot{Page \thepage} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand\BackgroundIm{ \put(0,0){ \parbox[b][\paperheight]{\paperwidth}{ \vfill \centering {\transparent{0.05} \includegraphics[height=\paperheight,width=\paperwidth, keepaspectratio]{gne}%%Background image \vfill }}}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \begin{titlepage} \new...