SlideShare una empresa de Scribd logo
1 de 49
INTRODUCTION TO OBJECT ORIENTED
      PROGRAMMING LAB




        PRACTICAL FILE




      BY: _____________
          B.Sc. IT – II
                          SUBMITED TO:
                            MS.NEETU GUPTA
1. WAP to calculate factorial of a given number n.

#include<conio.h>

#include<iostream.h>

void main()

{

int x=0;

int Fact=1;

cout<<"Enter number to calculate Factorial:";

cin>>x;

for(int c=1;c<=x;c++)

{

Fact=Fact * c;

}

cout<<"Factorial of number <<x << is: "<<Fact;

getch();

}




OUTPUT:
2. WAP to check whether a number is prime or not.

#include<iostream.h>

#include<conio.h>

int main()

{

Clrscr();

int num;

cout << "Enter a number ";

cin >> num;

int i=2;

while(i<=num-1)

{

if(num%i==0)

{

cout << "n" << num << " is not a prime number.";

break;

}

i++;

}

if(i==num)

cout << "n" << num << " is a prime number.";

getch();

}

OUTPUT:
3. WAP to print Fibonacci series of ‘n’ numbers, where n is given by the programmer.

#include<iostream.h>

#include<conio.h>

int main()

{

clrscr();

int a=0,b=1,c,n=0,lim;

cout<<"Enter the limit:n";

cin>>lim;

cout<<a<<"t"<<b<<"t";

while(n!=lim)

{

c=a+b;

cout<<c<<"t";

a=b;

b=c;

n++;

}

getch();

return 0;

}

OUTPUT:
4. WAP to do the following:
       a. Generate the following menu:
            1. Add two numbers.
            2. Subtract two numbers.
            3. Multiply two numbers.

                4. Divide two numbers.

                 5. Exit.
            b. Ask the user to input two integers and then input a choice from the menu. Perform all the
            arithmetic operations which have been offered by the menu. Checks for errors caused due to
            inappropriate entry by user and output a statement accordingly.


#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

void main()

{

clrscr();

int a,b,ch;

float c;

cout<<"Enter the first number";

cin>>a;

cout<<"Enter the second number";

cin>>b;

cout<<"n***************MENU******************";

cout<<"n1 ADD two numbers.";

cout<<"n2 SUBTRACT two numbers.";

cout<<"n3 MULTIPLY two numbers.";

cout<<"n4 DIVIDE two numbers.";

cout<<"n5 EXIT.";
cout<<"n PLEASE ENTER YOUR CHOICE:";

cin>>ch;

switch(ch)

{

case 1:

{

c=a+b;

cout<<"n The sum of the two numbers is:"<<c;

break;

}

case 2:

{

c=a-b;

cout<<"n The differnce of two numbers is:"<<c;

break;

}

case 3:

{

c=a*b;

cout<<"n The product of two numbers is:"<<c;

break;

}

case 4:

{

if(b==0)
{

cout<<"ERROR..!!!";

}

else

{

c=a/b;

cout<<"The division of two numbers is:"<<c;

}

case 5:

{

exit(1);

break;

}

default:

{

cout<<"n Wrong choice";

}

}

getch();

}

}
OUTPUT:




    5. WAP to read a set of numbers in an array & to find the largest of them.



#include<iostream.h>

#include<conio.h>

void main (void)

{

Clrscr();

int a[100];

int i,n,larg;

cout << "How many numbers are in the array?" << endl;

cinn >> n;

cout << "Enter the elements" << endl;

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

{

cin >> a[i];
}

cout << "Contents of the array" << endl;

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

{

cout << a[i] << 't';

}

cout << endl;

larg = a[0];

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

{

if (larg < a[i])

larg = a[i];

}

cout << "Largest value in the array =" << larg;

Getch();

}

OUTPUT:
6. WAP to implement bubble sort using arrays.



#include<iostream.h>

#include<conio.h>

int main()

{

clrscr();

int temp,n,arr[50];

cout<<"enter the no. of elements:";

cin>>n;

cout<<"Enter the elements of an array:n";

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

cin>>arr[i];

//Bubble sort method

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

{

for(int j=0;j<n-i-1;j++)

{

if(arr[j]>arr[j+1])

{

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}}}

cout<<"Now the sorted array is:n";
for(i=0;i<n;i++)

cout<<arr[i]<<"t";

getch();

return 0;

}



OUTPUT:




     7. WAP to sort a list of names in ascending order.



#include<iostream.h>

#include<conio.h>

#include<string.h>

void main()

{

char st[10][10],temp[10];

int i, j, n;

clrscr();

cout<<"Enter the no. of names:";

cin>>n;
cout<<"Enter the different names:";

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

cin>>st[i];

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

{

for(j=i; j< n-1; j++)

{

if(strcmp(st[i], st[j+1]) >0)

{

strcpy(temp,st[i]);

strcpy(st[i],st[j+1]);

strcpy(st[j+1],temp);

}

}

}

cout<<"Given names after ascending order:";

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

cout<< st[i];

getch();

}

OUTPUT:
8. WAP to read a set of numbers from keyboard & to find sum of all elements of the given array
       using a function.


#include<iostream.h>

Void add(int arr[],int n)    {

       Int I,sum=0;

For(i=1;i<=n;i++) {

          Sum=sum+arr[i];

}

Cout<<endl<<”the sum is”<<sum<<endl;

}

Void main() {

Int set[10],I,sum=0,limit;



Cout<<”enter number of entries: “;

Cin>>limit;



For(i=1;i<=limit;i++) {

       Cout<<”enter position “<<i<<” : “;

         Cin>>set[i];

}

Add(set,limit);



}



OUTPUT:
9. WAP to implement bubble sort using functions.

#include <stdio.h>

#include <iostream.h>

void bubbleSort(int *array,int length)//Bubble sort function

{

int i,j;

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

{

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

      {

if(array[i]>array[j])

{

int temp=array[i]; //swap

array[i]=array[j];

array[j]=temp;

}

}

}

}

void printElements(int *array,int length) //print array elements

{

int i=0;

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

cout<<array[i]<<endl;

}
void main()

{

int a[]={9,6,5,23,2,6,2,7,1,8};

bubbleSort(a,10);

printElements(a,10);

}



OUTPUT:




    10. WAP to exchange contents of two variables using call by value.

#include<iostream.h>

#include<conio.h>

void swap(int&,int&)

void main()

{

Clrscr(),

int a=1,b=2;

cout<<"Values before swap"<<endl;
cout<<"a="<<a<<endl;

cout<<"b="<<b<<endl;

swap(a,b);

cout<<"Values after swap"<<endl;

cout<<"a="<<a<<endl;

cout<<"b="<<b<<endl;

}

void swap(int& a, int& b)

{

int t;

t=a;

a=b;

b=t;

Getch(),

}

OUTPUT:
11. WAP to exchange contents of two variables using call by reference.



#include <iostream.h>

#include<conio.h>.

void swap( int &a, int &b )

{

int tmp; //Create a tmp int variable for storage

tmp = a;

a = b;

b = tmp;

return;

}

int main( int argc, char *argv[] )

{

Clrcsr();

int x = 3, y = 5; //

cout << "x: " << x << std::endl << "y: " << y << std::endl;

swap( x, y );

cout << "x: " << x << std::endl << "y: " << y << std::endl;

getch();

}

OUTPUT:
12. WAP to find the sum of three numbers using pointer to function method.

#include<iostream.h>

#include<conio.h>

int sum_num(int *,int *,int *);

int main()

{

clrscr();

int a,b,c;

cout<<"Enter three numbers:n";

cin>>a>>b>>c;

int sum=sum_num(&a,&b,&c);

cout<<"**In this program,sum of three numbers are calculatedn";

cout<<"by using pointers to a function**nn";

cout<<"Sum of three numbers are:n"<<sum;

getch();

return 0;

}

int sum_num(int *x,int *y,int *z)

{

int n=*x+ *y+ *z;

return n;

}
OUTPUT:




    13. WAP to display content of an array using pointers.

#include<iostream.h>

#include<conio.h>

void display(int *a,int size);

int main()

{

clrscr();

int i,n,arr[100];

cout<<"Enter the size of an array:n";

cin>>n;

cout<<"Enter the elements of an array:n";

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

cin>>arr[i];

display(arr,n);

getch();

return 0;

}
void display(int *a,int size)

{

cout<<"Details of an array using pointer are:n";

for(int i=0;i<size;i++)

cout<<*(a+i)<<endl;

}

OUTPUT:




    14. Calculate area of different geometrical figures (circle, rectangle,square, triangle) using
        function overloading.

#include<iostream.h>

Float calc(float r,float cons);

Int calc(int l,int h);

Int calc(int l);

Float calc(int l,int h,float cons);

Void main()
{

Int length,height;

Float radius;

Cout<<”enter radius of circle:”;<<radius;

Cout<<endl<<”the area of circle is:”<calc(radius,3.14)<<endl;

Cout<<”enter the length of rectangle”<<length;

Cout<<”enter the height of rectangle”<<height;

Cout<<endl<<”the area of rectangle is:”<calc(length,height)<<endl;

Cout<<”enter side of square”<<length;

Cout<<endl<<”the area of square is:”<calc(length)<<endl;

Cout<”enter base of triangle”;<<length;

Cout<”enter height of triangle”;<<height;

Cout<<endl<<”the area of triangle is:”<calc(length,height,0.5)<<endl;

}

Float calc(float r, float cons)

{return(cons*r*r);

}

Int calc(int l, int h)

{return(l*l);

}

Float calc(int l, int h,float cons)

{return (l*h*cons);

}
OUTPUT:




     15. WAP to add two complex numbers using friend function.

#include<iostream.h>

#include<conio.h>

Class cmplx

{

        Int real,imagin;

                Cout<<”ENTER THE REAL PART: “;

                Cin>>real;

                Cout<<”ENTER THE IMAGINARY PART: “;

                Cin>>imagin;

}

        Friend void sum(complx,complx);

};

Void sun(compx c1,complx c2)

        Cout<<”RESULT:”;

        Cout<<”*“<<c1.real<<”+ i”<<c1.imagin;

        Cout<<”++*“<<c2.real<<”+ i”<<c2.imagin;
Cout<<”+=”<<c1.real+c2.real<<”+ i”<<c1.imagin+c2.imagin;

}

Void main()

Complx op1,op2;

Cout<<endl<<”INPUT OPERAND 1----“;

Op1.get();

Cout<<endl<<”INPUT OPERAND 2----“;

Op2.get();

Sum(op1,op2); }




OUTPUT:
16. WAP to maintain the student record which contains Roll number, Name, Marks1, Marks2,
        Marks3 as data member and getdata(), display() and setdata() as member functions.



#include<iostream.h>

#include<conio.h>

Class student

{

Int roll, name, mark1, mark2, mark3, avg, total;

Public:

Void getdata()

Cout<<”enter roll number, name, marks”<<endl;

Cin>>roll>>name>>mark1>>mark2>>mark3;

}

Void setdata()

{

Total=mark1+mark2+mark3;

Avg=total/3;

}

Void display()

{

Cout<<roll;

Cout<<name;

Cout<<marks1;

Cout<<marks2;

Cout<<marks3;

Cout<<total;
Cout<<avg;

}

};

Void main()

{

Clrscr();

Student n i[10];

For (inti=0;i<=5;i++);

{

Ni[i].getdata();

Ni[i].getdata();

Ni[i].getdata();

Getch(); }

}

OUTPUT:
17. WAP to increment the employee salaries on the basis of there designation (Manager-5000,
        General Manager-10000, CEO-20000, worker-2000). Use employee name, id, designation and
        salary as data member and inc_sal as member function

#include<iostream.h>

#include<conio.h>

class employee

{

int age,basic,da,hra,tsal;

char name[20];

public:

void getdata()

{

cout<<"enter the name"<<endl;

cin>>name;

cout<<"enter the age"<<endl;

cin>>age;

cout<<"enter the basic salary"<<endl;

cin>>basic;

}

void caldata()

{

hra=.50*basic;

da=.12*basic;

tsal=basic+hra+da;

}

void display()
{

cout<<"name is:"<<name<<endl;

cout<<"age is:"<<age<<endl;

cout<<"basic salary is:"<<basic<<endl;

cout<<"hra is:"<<hra<<endl;

cout<<"da is:"<<da<<endl;

cout<<"toral salary is:"<<tsal<<endl;

}

};

void main()

{

clrscr();

employee e1;

e1.getdata();

e1.caldata();

e1.display();

getch();

}

OUTPUT:
18. Write a class bank, containing data member: Name of Depositor, A/c type, Type of A/c,
        Balance amount. Member function: To assign initial value, To deposit an amount, to withdraw
        an amount after checking the balance (which should be greater than Rs. 500) , To display
        name & balance.



#include<iostream.h>

#include<conio.h>

#include<string.h>

class bank

{

int bal,init,d_amt,wid_amt,bamt;

char n_depo[20],a_ctype[10],t_ac[10];

public:

bank()

{

init=10000;

}

void depositedata()

{

cout<<"enter the name of depositer:"<<endl;

cin>>n_depo;

cout<<"enter the a/c type:"<<endl;

cin>>a_ctype;

cout<<"enter the type of a/c:"<<endl;

cin>>t_ac;

cout<<"enter the deposit amount"<<endl;

cin>>d_amt;
bal=init+d_amt;

}

void withdarawdata()

{

if (bal>=500)

{

cout<<"amount to be withdrawn:"<<endl;

cin>>wid_amt;

bamt=bal-wid_amt;

}

else

{

cout<<"error"<<endl;

}

}

void display()

{

cout<<"name of depositer:"<<n_depo<<endl;

cout<<"deposite amount is"<<d_amt<<endl;

cout<<"balence after deposite"<<bal<<endl;

cout<<"withdraw amount"<<wid_amt<<endl;

cout<<"end balence"<<bamt<<endl;

}

};

void main()
{

clrscr();

bank b1;

b1.depositedata();

b1.withdarawdata();

b1.display();

getch();

}



OUTPUT:
19. WAP to define nested class ‘student_info’ which contains data members such as name, roll
        number and sex and also consists of one more class ‘date’ ,whose data members are day,
        month and year. The data is to be read from the keyboard & displayed on the screen.



#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>



class student_info

{

public: class date

        {

        private:

                   char day[20],month[20],year[20];

        public:

                   void input_date()

                   {

                           cout<<"Enter Date of Birth (dd/mm/yy):t";

                           cin>>day>>month>>year;

                           getch();



                   }

                   void disp()

                   {

                           cout<<"nDOB:t"<<day<<"-"<<month<<"-"<<year;
}

           };

private:

           char name[30],roll[30],sex[20];

           date d;




public:

           void input()

           {



                     cout<<"Enter the name of the student:t";

                     gets(name);

                     cout<<"Enter the roll of the student:t";

                     gets(roll);

                     cout<<"Enter the sex(male or female):t";

                     cin>>sex;

                     d.input_date();

           }

           void display()

           {

                     clrscr();

                     cout<<"Details of studentnn";

                     cout<<"Name:t"<<name<<"nRoll:t"<<roll<<"nSex:t"<<sex;
d.disp();

        }

};

int main()

{

        clrscr();

        student_info a;



        a.input();



        a.display();



        getch();

        return 0;

}



OUTPUT:
20. WAP to generate a series of Fibonacci numbers using copy constructor, where it is defined
         outside the class using scope resolution operator.



#include<iostream.h>

        {

                Public:

                          Fibonacci():limit(0)

                          {}

                          Fibonacci(int li):limit(li)

                          Int fibo=1,1=0,j=0;

                          Cout<<0<<””;

                          While(limit!=0)

                          Cout<<fibo<<””;

                          I=j;

                          J=fibo;

                          Fibo=i+j;

                          Limit--;

                }

        }

};

Void main()

        {

                Int n;

                Cout<<”Enter the number of the instances: “;

                Cin>>n;

                Fibonacci f(n);
Cout<<endl;

            }



OUTPUT:




    21. Write a class string to compare two strings, overload (= =) operator.

#include< iostream.h >

#include< conio.h >

#include< string.h >

const int SIZE=40;

class String

{

private:

char str [SIZE];

public:

String ()

{

strcpy (str," ");

}

String (char ch [])

{

strcpy (str, ch);
}

void getString ()

{

cout<< "Enter the string: -";

cin.get (str, SIZE);

}

int operator == (String s)

{

if (strcmp (str, s.str)==0)

return 1;

else

return 0;

}

};

void main ()

{

clrscr ();

String s1, s2, s3;

s1="Satavisha";

s2="Suddhashil";

s3.getString ();

if (s3==s1)

cout<< "1st and 3rd string are same.";

else if (s2==s3)

cout<< "2nd and 3rd string are same.";
else

cout<< "All strings are unique.";

getch ();

}



OUTPUT:




       22. Write a class to concatenate two strings, overload (+) operator.



#include<iostream.h>

#include<string>

Using namespace std;

Class mystring

{

          Char a[10,b[10];

          Public:

                    Void getdata()

          {

                    Cout<<”Enter first string=”;

                    Gets(a);

                    Cout<<”Enter second string=”;

                    Gets(b);

          }
};

Int main()

{

        Mystring x;

        x.getdata();

        +x;

        System(“pause”);

        Return 0;

}



OUTPUT:




     23. Create a class item, having two data members x & y, overload ‘-‘(unary operator) to change
         the sign of x and y.

#include<iostream.h>

Using namespace std;

Class item

{

        Int x,y;

        Public:

                   Void getdata()

                   {
Cout<<”Enter the vale of x & y=”;

                       Cin>>x;

                       Cin>>y;

               }

               Void operator –(void)

               {

                       X= -x;

                       Y= -y;

               }

               Void display()

               {

                       Cout<<”nx=”<<x<<”ny=”<<y;

               }

};

Int main()

{

Item x;

x.getdata();

-x;

x.display();

cout<<endl;

system(“pause”);

return 0;

}
OUTPUT:




    24. Create a class Employee. Derive 3 classes from this class namely, Programmer, Analyst &
        Project Leader. Take attributes and operations on your own. WAP to implement this with
        array of pointers.

#include<iostream.h>

#include<conio.h>

#include<string.h>

class employee

{

        private:

                   char name[20];

                   int salary;

        public :

                   void putdata(int sal, char nam[20])

            {      strcpy(name,nam);

                   salary=sal;}

char* getName(void)

{

        return name;

}

int getSal(void)
{

return salary;

}

};

class programmer:public employee

{

        private:

                   char skill[10];

        public:

                   programmer(char name[20],int sal,char skil[20])

        {

                   putData(sal,name);

                   strcpy(skill,skil);

        }

        void display(void)

        {

                   cout<<"nProgrammer : n";

                   cout<<"nName : "<<getName();

                   cout<<"nSalary : "<<getSal();

                   cout<<"nSkill : "<<skill;

        }

};

class analyst:public employee

{

        private:
char type[10];

       public:

                  analyst(char name[20],int sal,char typ[20])

       {

                  putData(sal,name);

                  strcpy(type,typ);

       }

       void display(void)

       {

                  cout<<"nn Analyst :n";

                  cout<<"nName :"<<getName();

                  cout<<"nsalary :"<<getSal();

                  cout<<"nType :"<<type;

       }

};

class proj_leader:public employee

{

       private:

                  char pName[10];

       public:

                  proj_leader(char name[20], int sal,char pNam[20])

{

putData(sal,name);

strcpy(pName,pNam);

}
};



void display(void){

clrscr();

proj_leader prl("akshay",10000,"software Development");

analyst al("amita",8600,"post");

programmer pl("xyz",12000,"C++");

prl.display();

al.display();

pl.display();

getch();

}



OUTPUT:
25. Create two classes namely Employee and Qualification. Using multiple inheritance derive two
    classes Scientist and Manager. Take suitable attributes & operations. WAP to implement this
    class hierarchy.

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

class employee

{

     char empname[10];

     int empid;

     public:

               void getemp()

     {

               cout<<endl<<"Enter Emlpoyee Name :";

               gets(empname);

               cout<<"Enter Employee Id";

               cin>>empid;

     }

     void display()

     {

               cout<<endl<<"Name :"<<empname;

               cout<<endl<<"Id :"<<empid;

     }

};

class qualification

{
int exp;

     public:

                void getqual()

                {

                        cout<<"Enter Year Of Working Experience :";

                        cin>>exp;

                }

                void dispqual()

         {              cout<<endl<<"Experiece="<<exp<<"years";

                }

};

class scientist:public employee,public qualification

{

     int projid;

     public:

                void getproject()

     {

                        cout<<"Enter Project Id :";

                        cin>>projid;

     }

     void dispproj()

     {

                cout<<endl<<"PROJECT ID : "<<projid;

     }

};
class manager:public employee,public qualification

{

     int groupid;

     public:

                 void getgroup()

                 {

                        cout<<"Enter Group Id :";

                        cin>>groupid;



     }

                 void dispgroup()

     {

                 cout<<endl<<"Group ID :"<<groupid;

     }

};

void main()

{

     clrscr();

     scientist s;

     manager m;

     cout<<"FOR SCIENTIST::::"<<endl;

     s.getemp();

     s.getqual();

     s.getproject();

     s.display();
s.dispqual();

    s.dispproj();

    cout<<endl<<endl<<endl<<"FOR MANAGER::::"<<endl;

    m.getemp();

    m.getqual();

    m.getgroup();

    m.display();

    m.dispqual();

    m.dispgroup();

    getch();

}



OUTPUT:
26. WAP to read data from keyboard & write it to the file. After writing is completed, the file is
        closed. The program again opens the same file and reads it.

#include<iostream.h>

#include<fstream.h>

Void main(void)

Char string[255];

Int ch;

Cout<<”nMENUn)Write To Filen2)Read From FilenEnter Choice : “;

Cin>>ch;

Switch(ch)

{

          Case 1:

                    Cout<<’nEnter String To Write To File :”;

                    Cin>>string;

                    Ofstream fout;

                    Fout.open(“myfile.txt”);

                    Fout<<string;

                    Fout<<flush;

                    Fout.close();

                    Break;

          Case 2:

                    Ifstream fin;

                    Fin.open(“myfile.txt”)

                    Fin>>string;

                    Cout<<”nFile Read : n”<<string;

                    Fin.close();
Break;

      Default:

                 Cout<<”INVALID CHOICE”;

      }

}




OUTPUT:

Más contenido relacionado

La actualidad más candente

High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14Matthieu Garrigues
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++Bharat Kalia
 
Computer science project work
Computer science project workComputer science project work
Computer science project workrahulchamp2345
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programsAbhishek Jena
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Rushil Aggarwal
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Aman Deep
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILEAnushka Rai
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-yearAMIT SINGH
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
C++ project on police station software
C++ project on police station softwareC++ project on police station software
C++ project on police station softwaredharmenderlodhi021
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++Patrick Viafore
 

La actualidad más candente (20)

High performance web programming with C++14
High performance web programming with C++14High performance web programming with C++14
High performance web programming with C++14
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
C++ file
C++ fileC++ file
C++ file
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
informatics practices practical file
informatics practices practical fileinformatics practices practical file
informatics practices practical file
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
C program
C programC program
C program
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-year
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
C++ project on police station software
C++ project on police station softwareC++ project on police station software
C++ project on police station software
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
 

Similar a C++ file

2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Assignment#1
Assignment#1Assignment#1
Assignment#1NA000000
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 
Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solvingSyed Umair
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 

Similar a C++ file (20)

Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
C++ practical
C++ practicalC++ practical
C++ practical
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Assignment#1
Assignment#1Assignment#1
Assignment#1
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
C++
C++C++
C++
 
Oops lab manual
Oops lab manualOops lab manual
Oops lab manual
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solving
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 

Más de Mukund Trivedi

Más de Mukund Trivedi (20)

System development life cycle (sdlc)
System development life cycle (sdlc)System development life cycle (sdlc)
System development life cycle (sdlc)
 
Process of design
Process of designProcess of design
Process of design
 
New file and form 2
New file and form 2New file and form 2
New file and form 2
 
File organisation
File organisationFile organisation
File organisation
 
Evaluation
EvaluationEvaluation
Evaluation
 
Database
DatabaseDatabase
Database
 
Case tools
Case toolsCase tools
Case tools
 
Evaluation
EvaluationEvaluation
Evaluation
 
Dfd final
Dfd finalDfd final
Dfd final
 
Sad
SadSad
Sad
 
Ff40fnatural resources (1)
Ff40fnatural resources (1)Ff40fnatural resources (1)
Ff40fnatural resources (1)
 
Ff40fnatural resources
Ff40fnatural resourcesFf40fnatural resources
Ff40fnatural resources
 
F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)F58fbnatural resources 2 (1)
F58fbnatural resources 2 (1)
 
F58fbnatural resources 2
F58fbnatural resources 2F58fbnatural resources 2
F58fbnatural resources 2
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
Ee2fbunit 7
Ee2fbunit 7Ee2fbunit 7
Ee2fbunit 7
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
 

Último

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Último (20)

ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 

C++ file

  • 1. INTRODUCTION TO OBJECT ORIENTED PROGRAMMING LAB PRACTICAL FILE BY: _____________ B.Sc. IT – II SUBMITED TO: MS.NEETU GUPTA
  • 2. 1. WAP to calculate factorial of a given number n. #include<conio.h> #include<iostream.h> void main() { int x=0; int Fact=1; cout<<"Enter number to calculate Factorial:"; cin>>x; for(int c=1;c<=x;c++) { Fact=Fact * c; } cout<<"Factorial of number <<x << is: "<<Fact; getch(); } OUTPUT:
  • 3. 2. WAP to check whether a number is prime or not. #include<iostream.h> #include<conio.h> int main() { Clrscr(); int num; cout << "Enter a number "; cin >> num; int i=2; while(i<=num-1) { if(num%i==0) { cout << "n" << num << " is not a prime number."; break; } i++; } if(i==num) cout << "n" << num << " is a prime number."; getch(); } OUTPUT:
  • 4. 3. WAP to print Fibonacci series of ‘n’ numbers, where n is given by the programmer. #include<iostream.h> #include<conio.h> int main() { clrscr(); int a=0,b=1,c,n=0,lim; cout<<"Enter the limit:n"; cin>>lim; cout<<a<<"t"<<b<<"t"; while(n!=lim) { c=a+b; cout<<c<<"t"; a=b; b=c; n++; } getch(); return 0; } OUTPUT:
  • 5. 4. WAP to do the following: a. Generate the following menu: 1. Add two numbers. 2. Subtract two numbers. 3. Multiply two numbers. 4. Divide two numbers. 5. Exit. b. Ask the user to input two integers and then input a choice from the menu. Perform all the arithmetic operations which have been offered by the menu. Checks for errors caused due to inappropriate entry by user and output a statement accordingly. #include<iostream.h> #include<conio.h> #include<stdlib.h> void main() { clrscr(); int a,b,ch; float c; cout<<"Enter the first number"; cin>>a; cout<<"Enter the second number"; cin>>b; cout<<"n***************MENU******************"; cout<<"n1 ADD two numbers."; cout<<"n2 SUBTRACT two numbers."; cout<<"n3 MULTIPLY two numbers."; cout<<"n4 DIVIDE two numbers."; cout<<"n5 EXIT.";
  • 6. cout<<"n PLEASE ENTER YOUR CHOICE:"; cin>>ch; switch(ch) { case 1: { c=a+b; cout<<"n The sum of the two numbers is:"<<c; break; } case 2: { c=a-b; cout<<"n The differnce of two numbers is:"<<c; break; } case 3: { c=a*b; cout<<"n The product of two numbers is:"<<c; break; } case 4: { if(b==0)
  • 7. { cout<<"ERROR..!!!"; } else { c=a/b; cout<<"The division of two numbers is:"<<c; } case 5: { exit(1); break; } default: { cout<<"n Wrong choice"; } } getch(); } }
  • 8. OUTPUT: 5. WAP to read a set of numbers in an array & to find the largest of them. #include<iostream.h> #include<conio.h> void main (void) { Clrscr(); int a[100]; int i,n,larg; cout << "How many numbers are in the array?" << endl; cinn >> n; cout << "Enter the elements" << endl; for (i=0;i<=n-1;++i) { cin >> a[i];
  • 9. } cout << "Contents of the array" << endl; for (i=0; i<=n-1;++i) { cout << a[i] << 't'; } cout << endl; larg = a[0]; for (i=0;i<=n-1;++i) { if (larg < a[i]) larg = a[i]; } cout << "Largest value in the array =" << larg; Getch(); } OUTPUT:
  • 10. 6. WAP to implement bubble sort using arrays. #include<iostream.h> #include<conio.h> int main() { clrscr(); int temp,n,arr[50]; cout<<"enter the no. of elements:"; cin>>n; cout<<"Enter the elements of an array:n"; for(int i=0;i<n;i++) cin>>arr[i]; //Bubble sort method for(i=0;i<n;i++) { for(int j=0;j<n-i-1;j++) { if(arr[j]>arr[j+1]) { temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; }}} cout<<"Now the sorted array is:n";
  • 11. for(i=0;i<n;i++) cout<<arr[i]<<"t"; getch(); return 0; } OUTPUT: 7. WAP to sort a list of names in ascending order. #include<iostream.h> #include<conio.h> #include<string.h> void main() { char st[10][10],temp[10]; int i, j, n; clrscr(); cout<<"Enter the no. of names:"; cin>>n;
  • 12. cout<<"Enter the different names:"; for(i=0; i< n; i++) cin>>st[i]; for(i=0; i< n; i++) { for(j=i; j< n-1; j++) { if(strcmp(st[i], st[j+1]) >0) { strcpy(temp,st[i]); strcpy(st[i],st[j+1]); strcpy(st[j+1],temp); } } } cout<<"Given names after ascending order:"; for(i=0;i<5;i++) cout<< st[i]; getch(); } OUTPUT:
  • 13. 8. WAP to read a set of numbers from keyboard & to find sum of all elements of the given array using a function. #include<iostream.h> Void add(int arr[],int n) { Int I,sum=0; For(i=1;i<=n;i++) { Sum=sum+arr[i]; } Cout<<endl<<”the sum is”<<sum<<endl; } Void main() { Int set[10],I,sum=0,limit; Cout<<”enter number of entries: “; Cin>>limit; For(i=1;i<=limit;i++) { Cout<<”enter position “<<i<<” : “; Cin>>set[i]; } Add(set,limit); } OUTPUT:
  • 14. 9. WAP to implement bubble sort using functions. #include <stdio.h> #include <iostream.h> void bubbleSort(int *array,int length)//Bubble sort function { int i,j; for(i=0;i<10;i++) { for(j=0;j<i;j++) { if(array[i]>array[j]) { int temp=array[i]; //swap array[i]=array[j]; array[j]=temp; } } } } void printElements(int *array,int length) //print array elements { int i=0; for(i=0;i<10;i++) cout<<array[i]<<endl; }
  • 15. void main() { int a[]={9,6,5,23,2,6,2,7,1,8}; bubbleSort(a,10); printElements(a,10); } OUTPUT: 10. WAP to exchange contents of two variables using call by value. #include<iostream.h> #include<conio.h> void swap(int&,int&) void main() { Clrscr(), int a=1,b=2; cout<<"Values before swap"<<endl;
  • 17. 11. WAP to exchange contents of two variables using call by reference. #include <iostream.h> #include<conio.h>. void swap( int &a, int &b ) { int tmp; //Create a tmp int variable for storage tmp = a; a = b; b = tmp; return; } int main( int argc, char *argv[] ) { Clrcsr(); int x = 3, y = 5; // cout << "x: " << x << std::endl << "y: " << y << std::endl; swap( x, y ); cout << "x: " << x << std::endl << "y: " << y << std::endl; getch(); } OUTPUT:
  • 18. 12. WAP to find the sum of three numbers using pointer to function method. #include<iostream.h> #include<conio.h> int sum_num(int *,int *,int *); int main() { clrscr(); int a,b,c; cout<<"Enter three numbers:n"; cin>>a>>b>>c; int sum=sum_num(&a,&b,&c); cout<<"**In this program,sum of three numbers are calculatedn"; cout<<"by using pointers to a function**nn"; cout<<"Sum of three numbers are:n"<<sum; getch(); return 0; } int sum_num(int *x,int *y,int *z) { int n=*x+ *y+ *z; return n; }
  • 19. OUTPUT: 13. WAP to display content of an array using pointers. #include<iostream.h> #include<conio.h> void display(int *a,int size); int main() { clrscr(); int i,n,arr[100]; cout<<"Enter the size of an array:n"; cin>>n; cout<<"Enter the elements of an array:n"; for(i=0;i<n;i++) cin>>arr[i]; display(arr,n); getch(); return 0; }
  • 20. void display(int *a,int size) { cout<<"Details of an array using pointer are:n"; for(int i=0;i<size;i++) cout<<*(a+i)<<endl; } OUTPUT: 14. Calculate area of different geometrical figures (circle, rectangle,square, triangle) using function overloading. #include<iostream.h> Float calc(float r,float cons); Int calc(int l,int h); Int calc(int l); Float calc(int l,int h,float cons); Void main()
  • 21. { Int length,height; Float radius; Cout<<”enter radius of circle:”;<<radius; Cout<<endl<<”the area of circle is:”<calc(radius,3.14)<<endl; Cout<<”enter the length of rectangle”<<length; Cout<<”enter the height of rectangle”<<height; Cout<<endl<<”the area of rectangle is:”<calc(length,height)<<endl; Cout<<”enter side of square”<<length; Cout<<endl<<”the area of square is:”<calc(length)<<endl; Cout<”enter base of triangle”;<<length; Cout<”enter height of triangle”;<<height; Cout<<endl<<”the area of triangle is:”<calc(length,height,0.5)<<endl; } Float calc(float r, float cons) {return(cons*r*r); } Int calc(int l, int h) {return(l*l); } Float calc(int l, int h,float cons) {return (l*h*cons); }
  • 22. OUTPUT: 15. WAP to add two complex numbers using friend function. #include<iostream.h> #include<conio.h> Class cmplx { Int real,imagin; Cout<<”ENTER THE REAL PART: “; Cin>>real; Cout<<”ENTER THE IMAGINARY PART: “; Cin>>imagin; } Friend void sum(complx,complx); }; Void sun(compx c1,complx c2) Cout<<”RESULT:”; Cout<<”*“<<c1.real<<”+ i”<<c1.imagin; Cout<<”++*“<<c2.real<<”+ i”<<c2.imagin;
  • 23. Cout<<”+=”<<c1.real+c2.real<<”+ i”<<c1.imagin+c2.imagin; } Void main() Complx op1,op2; Cout<<endl<<”INPUT OPERAND 1----“; Op1.get(); Cout<<endl<<”INPUT OPERAND 2----“; Op2.get(); Sum(op1,op2); } OUTPUT:
  • 24. 16. WAP to maintain the student record which contains Roll number, Name, Marks1, Marks2, Marks3 as data member and getdata(), display() and setdata() as member functions. #include<iostream.h> #include<conio.h> Class student { Int roll, name, mark1, mark2, mark3, avg, total; Public: Void getdata() Cout<<”enter roll number, name, marks”<<endl; Cin>>roll>>name>>mark1>>mark2>>mark3; } Void setdata() { Total=mark1+mark2+mark3; Avg=total/3; } Void display() { Cout<<roll; Cout<<name; Cout<<marks1; Cout<<marks2; Cout<<marks3; Cout<<total;
  • 25. Cout<<avg; } }; Void main() { Clrscr(); Student n i[10]; For (inti=0;i<=5;i++); { Ni[i].getdata(); Ni[i].getdata(); Ni[i].getdata(); Getch(); } } OUTPUT:
  • 26. 17. WAP to increment the employee salaries on the basis of there designation (Manager-5000, General Manager-10000, CEO-20000, worker-2000). Use employee name, id, designation and salary as data member and inc_sal as member function #include<iostream.h> #include<conio.h> class employee { int age,basic,da,hra,tsal; char name[20]; public: void getdata() { cout<<"enter the name"<<endl; cin>>name; cout<<"enter the age"<<endl; cin>>age; cout<<"enter the basic salary"<<endl; cin>>basic; } void caldata() { hra=.50*basic; da=.12*basic; tsal=basic+hra+da; } void display()
  • 27. { cout<<"name is:"<<name<<endl; cout<<"age is:"<<age<<endl; cout<<"basic salary is:"<<basic<<endl; cout<<"hra is:"<<hra<<endl; cout<<"da is:"<<da<<endl; cout<<"toral salary is:"<<tsal<<endl; } }; void main() { clrscr(); employee e1; e1.getdata(); e1.caldata(); e1.display(); getch(); } OUTPUT:
  • 28. 18. Write a class bank, containing data member: Name of Depositor, A/c type, Type of A/c, Balance amount. Member function: To assign initial value, To deposit an amount, to withdraw an amount after checking the balance (which should be greater than Rs. 500) , To display name & balance. #include<iostream.h> #include<conio.h> #include<string.h> class bank { int bal,init,d_amt,wid_amt,bamt; char n_depo[20],a_ctype[10],t_ac[10]; public: bank() { init=10000; } void depositedata() { cout<<"enter the name of depositer:"<<endl; cin>>n_depo; cout<<"enter the a/c type:"<<endl; cin>>a_ctype; cout<<"enter the type of a/c:"<<endl; cin>>t_ac; cout<<"enter the deposit amount"<<endl; cin>>d_amt;
  • 29. bal=init+d_amt; } void withdarawdata() { if (bal>=500) { cout<<"amount to be withdrawn:"<<endl; cin>>wid_amt; bamt=bal-wid_amt; } else { cout<<"error"<<endl; } } void display() { cout<<"name of depositer:"<<n_depo<<endl; cout<<"deposite amount is"<<d_amt<<endl; cout<<"balence after deposite"<<bal<<endl; cout<<"withdraw amount"<<wid_amt<<endl; cout<<"end balence"<<bamt<<endl; } }; void main()
  • 31. 19. WAP to define nested class ‘student_info’ which contains data members such as name, roll number and sex and also consists of one more class ‘date’ ,whose data members are day, month and year. The data is to be read from the keyboard & displayed on the screen. #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> class student_info { public: class date { private: char day[20],month[20],year[20]; public: void input_date() { cout<<"Enter Date of Birth (dd/mm/yy):t"; cin>>day>>month>>year; getch(); } void disp() { cout<<"nDOB:t"<<day<<"-"<<month<<"-"<<year;
  • 32. } }; private: char name[30],roll[30],sex[20]; date d; public: void input() { cout<<"Enter the name of the student:t"; gets(name); cout<<"Enter the roll of the student:t"; gets(roll); cout<<"Enter the sex(male or female):t"; cin>>sex; d.input_date(); } void display() { clrscr(); cout<<"Details of studentnn"; cout<<"Name:t"<<name<<"nRoll:t"<<roll<<"nSex:t"<<sex;
  • 33. d.disp(); } }; int main() { clrscr(); student_info a; a.input(); a.display(); getch(); return 0; } OUTPUT:
  • 34. 20. WAP to generate a series of Fibonacci numbers using copy constructor, where it is defined outside the class using scope resolution operator. #include<iostream.h> { Public: Fibonacci():limit(0) {} Fibonacci(int li):limit(li) Int fibo=1,1=0,j=0; Cout<<0<<””; While(limit!=0) Cout<<fibo<<””; I=j; J=fibo; Fibo=i+j; Limit--; } } }; Void main() { Int n; Cout<<”Enter the number of the instances: “; Cin>>n; Fibonacci f(n);
  • 35. Cout<<endl; } OUTPUT: 21. Write a class string to compare two strings, overload (= =) operator. #include< iostream.h > #include< conio.h > #include< string.h > const int SIZE=40; class String { private: char str [SIZE]; public: String () { strcpy (str," "); } String (char ch []) { strcpy (str, ch);
  • 36. } void getString () { cout<< "Enter the string: -"; cin.get (str, SIZE); } int operator == (String s) { if (strcmp (str, s.str)==0) return 1; else return 0; } }; void main () { clrscr (); String s1, s2, s3; s1="Satavisha"; s2="Suddhashil"; s3.getString (); if (s3==s1) cout<< "1st and 3rd string are same."; else if (s2==s3) cout<< "2nd and 3rd string are same.";
  • 37. else cout<< "All strings are unique."; getch (); } OUTPUT: 22. Write a class to concatenate two strings, overload (+) operator. #include<iostream.h> #include<string> Using namespace std; Class mystring { Char a[10,b[10]; Public: Void getdata() { Cout<<”Enter first string=”; Gets(a); Cout<<”Enter second string=”; Gets(b); }
  • 38. }; Int main() { Mystring x; x.getdata(); +x; System(“pause”); Return 0; } OUTPUT: 23. Create a class item, having two data members x & y, overload ‘-‘(unary operator) to change the sign of x and y. #include<iostream.h> Using namespace std; Class item { Int x,y; Public: Void getdata() {
  • 39. Cout<<”Enter the vale of x & y=”; Cin>>x; Cin>>y; } Void operator –(void) { X= -x; Y= -y; } Void display() { Cout<<”nx=”<<x<<”ny=”<<y; } }; Int main() { Item x; x.getdata(); -x; x.display(); cout<<endl; system(“pause”); return 0; }
  • 40. OUTPUT: 24. Create a class Employee. Derive 3 classes from this class namely, Programmer, Analyst & Project Leader. Take attributes and operations on your own. WAP to implement this with array of pointers. #include<iostream.h> #include<conio.h> #include<string.h> class employee { private: char name[20]; int salary; public : void putdata(int sal, char nam[20]) { strcpy(name,nam); salary=sal;} char* getName(void) { return name; } int getSal(void)
  • 41. { return salary; } }; class programmer:public employee { private: char skill[10]; public: programmer(char name[20],int sal,char skil[20]) { putData(sal,name); strcpy(skill,skil); } void display(void) { cout<<"nProgrammer : n"; cout<<"nName : "<<getName(); cout<<"nSalary : "<<getSal(); cout<<"nSkill : "<<skill; } }; class analyst:public employee { private:
  • 42. char type[10]; public: analyst(char name[20],int sal,char typ[20]) { putData(sal,name); strcpy(type,typ); } void display(void) { cout<<"nn Analyst :n"; cout<<"nName :"<<getName(); cout<<"nsalary :"<<getSal(); cout<<"nType :"<<type; } }; class proj_leader:public employee { private: char pName[10]; public: proj_leader(char name[20], int sal,char pNam[20]) { putData(sal,name); strcpy(pName,pNam); }
  • 43. }; void display(void){ clrscr(); proj_leader prl("akshay",10000,"software Development"); analyst al("amita",8600,"post"); programmer pl("xyz",12000,"C++"); prl.display(); al.display(); pl.display(); getch(); } OUTPUT:
  • 44. 25. Create two classes namely Employee and Qualification. Using multiple inheritance derive two classes Scientist and Manager. Take suitable attributes & operations. WAP to implement this class hierarchy. #include<iostream.h> #include<conio.h> #include<stdio.h> class employee { char empname[10]; int empid; public: void getemp() { cout<<endl<<"Enter Emlpoyee Name :"; gets(empname); cout<<"Enter Employee Id"; cin>>empid; } void display() { cout<<endl<<"Name :"<<empname; cout<<endl<<"Id :"<<empid; } }; class qualification {
  • 45. int exp; public: void getqual() { cout<<"Enter Year Of Working Experience :"; cin>>exp; } void dispqual() { cout<<endl<<"Experiece="<<exp<<"years"; } }; class scientist:public employee,public qualification { int projid; public: void getproject() { cout<<"Enter Project Id :"; cin>>projid; } void dispproj() { cout<<endl<<"PROJECT ID : "<<projid; } };
  • 46. class manager:public employee,public qualification { int groupid; public: void getgroup() { cout<<"Enter Group Id :"; cin>>groupid; } void dispgroup() { cout<<endl<<"Group ID :"<<groupid; } }; void main() { clrscr(); scientist s; manager m; cout<<"FOR SCIENTIST::::"<<endl; s.getemp(); s.getqual(); s.getproject(); s.display();
  • 47. s.dispqual(); s.dispproj(); cout<<endl<<endl<<endl<<"FOR MANAGER::::"<<endl; m.getemp(); m.getqual(); m.getgroup(); m.display(); m.dispqual(); m.dispgroup(); getch(); } OUTPUT:
  • 48. 26. WAP to read data from keyboard & write it to the file. After writing is completed, the file is closed. The program again opens the same file and reads it. #include<iostream.h> #include<fstream.h> Void main(void) Char string[255]; Int ch; Cout<<”nMENUn)Write To Filen2)Read From FilenEnter Choice : “; Cin>>ch; Switch(ch) { Case 1: Cout<<’nEnter String To Write To File :”; Cin>>string; Ofstream fout; Fout.open(“myfile.txt”); Fout<<string; Fout<<flush; Fout.close(); Break; Case 2: Ifstream fin; Fin.open(“myfile.txt”) Fin>>string; Cout<<”nFile Read : n”<<string; Fin.close();
  • 49. Break; Default: Cout<<”INVALID CHOICE”; } } OUTPUT: