SlideShare uma empresa 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:

Mais conteúdo relacionado

Mais procurados

Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple InheritanceBhavyaJain137
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C BUBT
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloadingHaresh Jaiswal
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
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
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
C programs
C programsC programs
C programsMinu S
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given numberMainak Sasmal
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 

Mais procurados (20)

Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
Chapter 1 : Balagurusamy_ Programming ANsI in C
Chapter 1  :  Balagurusamy_ Programming ANsI in C Chapter 1  :  Balagurusamy_ Programming ANsI in C
Chapter 1 : Balagurusamy_ Programming ANsI in C
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in 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)
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C programs
C programsC programs
C programs
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Python Programming
Python Programming Python Programming
Python Programming
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 

Destaque

12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
Physics Practical Notes Class 12 CBSE Final
Physics Practical Notes Class 12 CBSE FinalPhysics Practical Notes Class 12 CBSE Final
Physics Practical Notes Class 12 CBSE FinalMuhammad Jassim
 
file handling c++
file handling c++file handling c++
file handling c++Guddu Spy
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Self-employed
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionRai University
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cppgourav kottawar
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALPrabhu D
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its functionFrankie Jones
 
File handling in C++
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
 
Computer science study material
Computer science study materialComputer science study material
Computer science study materialSwarup Kumar Boro
 

Destaque (20)

12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Physics Practical Notes Class 12 CBSE Final
Physics Practical Notes Class 12 CBSE FinalPhysics Practical Notes Class 12 CBSE Final
Physics Practical Notes Class 12 CBSE Final
 
file handling c++
file handling c++file handling c++
file handling c++
 
Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12Computer Science Investigatory Project Class 12
Computer Science Investigatory Project Class 12
 
Bca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroductionBca 2nd sem u-1 iintroduction
Bca 2nd sem u-1 iintroduction
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cpp
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
8 header files
8 header files8 header files
8 header files
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Computer science study material
Computer science study materialComputer science study material
Computer science study material
 

Semelhante a C++ file

Semelhante a C++ file (20)

C++ file
C++ fileC++ file
C++ file
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
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
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
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
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
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
 

Mais 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
 
C++ file
C++ fileC++ file
C++ file
 
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
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

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: