C++ List of Experiment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

C++ List of Experiment

WRITE A PROGRAM TO ILLUSTRATE CLASS AND OBJECT WRITE A PROGRAM TO ILLUSTRATE ARITHMETIC EXPRESSION WAP TO ILLUSTRATE ARRAY WAP TO ILLUSTRATE FUNCTION WAP TO ILLUSTRATE CONSTRUCTOR WAP TO ILLUSTRATE CONSTRUCTOR WITH PARAMETER WAP TO ILLUSTRATE INHERITANCE WAP TO ILLUSTRATE FUNCTION OVERLOADING

/*write a program to illustrate class and object*/ #include<iostream.h> #include<conio.h> class deepak { private: int a,b,c; public: void getdata(); void showdata(); void sum(); }; void deepak::getdata() { cout<<"enter tha a,b"; cin>>a>>b; } void deepak::showdata() { cout<<"a is"<<a<<endl; cout<<"b is "<<b<<endl; } void deepak::sum() { c=a+b; cout<<"the sum is"<<c; } void main() { clrscr(); deepak d; d.getdata(); d.showdata(); d.sum();

getch(); }

Output

/*write a program to illustrate arithmetic expression*/ #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,result; float div_result; char choice; cout<<"enter a and b"; cin>>a>>b; cout<<"enter the operation you want to perform"<<endl; cout<<"+ for add"<<endl<<"- for substraction"<<endl; cout<<"* for multiplication"<<endl<<"/ for division"<<endl<<"% for reminder"<<endl; cin>>choice; switch(choice) { case '+': result=a+b; cout<<"the sum is "<<result; break; case '-': result=a-b; cout<<"the substraction is "<<result; break; case '*': result=a*b; cout<<"the multiplication is "<<result; break; case '/': div_result=(float)a/b; cout<<"the division is "<<div_result; break; case '%':

result=a%b; cout<<"the reminder is "<<result; break; default: cout<<"wrong input"; break; } getch(); }

Output

/* WAP TO ILLUSTRATE ARRAY*/

#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[10],i,sum=0; cout<<"enter the ten numbers"; for(i=0;i<=9;i++) { cin>>a[i]; } for(i=0;i<=9;i++) { cout<<a[i]<<endl; sum=sum+a[i]; } cout<<"the sum of all these ten numbers are:"<<endl<<sum; getch(); }

Output:

/* WAP TO ILLUSTRATE FUNCTION*/ #include<iostream.h> #include<conio.h> void sum(int a, int b); //function declartion

void main() { clrscr(); int x,y; cout<<"enter the x and y"; cin>>x>>y; sum(x,y); //function call getch(); } void sum(int a, int b) //function defination { int c; c=a+b; cout<<"the sum is "<<c<<endl; }

Output:

/*WAP TO ILLUSTRATE CONSTRUCTOR*/ #include<iostream.h> #include<conio.h> class sirt { public: sirt() { cout<<"my name is deepak"; } }; void main() { clrscr(); sirt s; getch(); }

Output:

/*WAP TO ILLUSTRATE CONSTRUCTOR WITH PARAMETER*/ #include<iostream.h> #include<conio.h> class sirt1 { public: sirt1(int x, int y) { int z; z=x+y; cout<<"the sum is "<<endl<<z; } }; void main() { clrscr(); sirt1 s(20,30); getch(); }

Output:

/*WAP TO ILLUSTRATE INHERITANCE */ #include<iostream.h> #include<conio.h> class sirt { protected: int x,y; public: void getdata(); void showdata(); }; class sirt1: public sirt { private: int z; public : void sum(); }; void sirt::getdata() { cout<<"enter x"; cin>>x; cout<<"enter y"; cin>>y; } void sirt::showdata() { cout<<"the x is"<<x<<endl; cout<<"the y is "<<y<<endl; } void sirt1::sum() { z=x+y; cout<<"the sum is"<<z<<endl; }

void main() { clrscr(); sirt1 s; s.getdata(); s.showdata(); s.sum(); getch(); }

OUTPUT:

/*WAP TO ILLUSTRATE FUNCTION OVERLOADING */ #include<iostream.h> #include<conio.h> class sirt { private: int x,y,z; public: void getdata(); void sum(); void sum(int a,int y); void sum(int i,int j, int k); }; void sirt::getdata() { cout<<"enter x"; cin>>x; cout<<"enter y"; cin>>y; } void sirt::sum() { int z; z=x+y; cout<<"the sum is "<<z<<endl; } void sirt::sum(int a,int b) { int c; c=a+b; cout<<"the sum is "<<c<<endl; } void sirt::sum(int i, int j, int k)

{ int l; l=i+j+k; cout<<"the sum is"<<l<<endl; } void main() { clrscr(); sirt s; s.getdata(); s.sum(); s.sum(10,20); s.sum(50,100,150); getch(); }

OUTPUT:

SQL

Create command: Syntax of create table command:


create table table_name(coloumname dataytpe(size), coloumname dataytpe(size), );
Example: SQL> create table student(Student_name varchar(20), student_id varchar(20), student_pdone number(12)); Table created. To check the table SQL> select * from student; no rows selected

To insert values in the table: Syntax:

insert into tablename valuer(valuse1, values2.)


Example: SQL> insert into student values('deepak','0521101',11111111); 1 row created. To check the table: SQL> select * from student; STUDENT_NAME -------------------deepak STUDENT_ID -------------------0521101 STUDENT_PDONE ------------11111111

SQL> insert into student values('rahul','0521102',1212121); 1 row created. SQL> select * from student;

STUDENT_NAME -------------------deepak rahul

STUDENT_ID -------------------0521101 0521102

STUDENT_PDONE ------------11111111 1212121

Syntax of update command:

update tablename set columnname=expression, columnname=expression,.. where columnname=expression,


Example: SQL> update student set student_name='kamlesh' where student_name='rahul'; 1 row updated.

SQL> select * from student; STUDENT_NAME STUDENT_ID ------------------------------------deepak 0521101 kamlesh 0521102 Syntax of delete particular rows: STUDENT_PDONE -- ------------11111111 1212121

Delete from table where condition;


SQL> delete from student where student_id='0521101'; 1 row deleted. SQL> select * from student; STUDENT_NAME -------------------kamlesh STUDENT_ID ------------------0521102 STUDENT_PDONE - ------------1212121

Syntax of delete all rows:

Delete from tablename;

SQL> delete from student; 2 rows deleted. SQL> select * from student; no rows selected

You might also like