Beruflich Dokumente
Kultur Dokumente
//WRITE A PROGRAM TO CONVERT A LOWERCASE LETTER TO UPPERCASE CHARACTER USING CONDITIONAL OPERATOR.
#include <iostream.h> #include <conio.h> void main() { char c1; clrscr(); cout<<"enter a character="; cin>>c1; char c2=(c1>='a'&&c1<='z')?('A'+c1-'a'):c1; cout<<"Uppercase equivalent="<<c2; getch(); } /*****OUTPUT enter a character=m Uppercase equivalent=M */
SGHCMT
SGHCMT
2\\WRITE A PROGRAM TO SUM OF DIGITS TO A NO. TO REDUCE IT UNTIL IT IS A SINGLE UNIT NO.
#include<iostream.h> #include<conio.h> class digit { private: int x,r,sum,sum1,r1; public: void dig(); }; void digit::dig() { cout<<"Enter a three digit no."<<endl; cin>>x; sum=0; while(x>0) { r=x%10; x=x/10; sum=sum+r; } if(sum>9) { sum1=0; while(sum>0) { r1=sum%10; sum=sum/10; sum1=sum1+r1; } cout<<"sum1:"<<sum1; }else { cout<<"Sum="<<sum; }} void main() { class digit d1; d1.dig(); getch(); }
SGHCMT
SGHCMT while(z<3); getch(); } /*******OUTPUT 1.IMPORTANCE OF BREAK 2.IMPORTANCE OF CONTINUE Which case = 1 1.IMPORTANCE OF BREAK 0 1 2 3 4 Which case = 2 S 1.IMPORTANCE OF CONTINUE 0 1 2 3 4 6 7 8 9 10 Which case = 3 */
SGHCMT
/****** OUTPUT
input the number=6 fact=720 */
SGHCMT
SGHCMT
SGHCMT
10
SGHCMT
9//WRITE A PROGRAM TO CALCULATE 2 INT, FLOAT, DOUBLE, CHAR NUMBER WITH FUNCTION OVERLOADING.
#include <iostream.h> #include <conio.h> void sum(int,int); void sum(float,float); void sum(double ,double ); void sum(char,char); void main() { int a,b; float c,d; double x,y; char m,n; clrscr(); sum(a,b); sum(c,d); sum(x,y); sum(m,n); getch(); } void sum(int a, int b) { int s; cout<<"the value of a & b="; cin>>a>>b; s=a+b; cout<<"\nthe value of sum in int is="<<s<<endl; return; } void sum(float c, float d) { float l; cout<<"\nthe value of c & d="; cin>>c>>d; l=c+d; cout<<"\nthe value of sum in float is="<<l<<endl; return; }
11
SGHCMT void sum(double x,double y) { double f; cout<<"\nthe value of x& y"; cin>>x>>y; f=x+y; cout<<"the value of double is="<<f<<endl; return; } Void sum(char m,char n) { int r; cout<<"\nthe value of m& n="; cin>>m>>n; r=m+n; cout<<"the value of char is="<<r; return; } /*******OUTPUT the value of a & b=9 6 the value of sum in int is=15 the value of c & d=2.5 5.7 the value of sum in float is=8.2 the value of x& y 2.00 3.56 the value of double is=5.56 the value of m& n=a b the value of char is=195*/
12
SGHCMT
8// SWAP 2 NO.S USING PASS BY VALUE, PASS BY ADDRESS, PASS BY REFERENCE
1) PASS BY VALUE #include <iostream.h> #include <conio.h> #include <stdlib.h> void swap(int a,int b); void main() { int a,b,z; clrscr(); cout<<"input the values of a & b"; cin>>a>>b; cout<<"\nthe value of a&b before swapping="<<a<<"\t"<<b; swap(a,b); getch(); } void swap(int a,int b) { int t; t=a; a=b; b=t; cout<<"\nthe value of a & b in called fun="<<a<<"\t"<<b<<endl; return; } /*******OUTPUT input the values of a & b 9 4 the value of a&b before swapping=9 4 the value of a & b in called fun=9 4 */
13
SGHCMT
2)PASS BY ADDRESS
#include <iostream.h> #include <conio.h> void swap(int *a,int *b); void main() { int a,b; clrscr(); cout<<"input the values of a & b"; cin>>a>>b; cout<<"\nthe value of a&b before swapping"<<"\t"<<a<<"\t"<<b; swap(&a,&b); cout<<"\nthe value of a&b after swapping"<<"\t"<<a<<"\t"<<b; getch(); } void swap(int *a,int *b) { int t; t=*a; *a=*b; *b=t; return; } /*****OUTPUT input the values of a & b 2 8 the value of a&b before swapping 2 the value of a&b after swapping 8 8 2*/
14
SGHCMT
3)PASS BY REFERENCE
#include<iostream.h> #include<conio.h> #include<stdio.h> void main() { int x,y; clrscr(); void swap(int &i,int &j); cout<<"Enter the value of X & Y"<<endl; cin>>x>>y; swap (x,y); cout<<"After swap the variables are"<<endl; cout<<"Value of X is"<<x<<endl<<"Value of Y is"<<y<<endl; getch(); } void swap(int &i,int &j) { int k; k=i; i=j; j=k; } /*cout<<"***output***"; Enter the value of X & Y 4 6 5 After swap the variables are Value of X is6 Value of Y is4*/
15
SGHCMT
SGHCMT for(i=k;i<=n;i++) a[i]=a[i+1]; n--; for(i=0;i<n;i++) cout<<"\n"<<a[i]; break; } } }while(z<3); getch(); } /*******OUTPUT how many elements 4 enter the element12 enter the element23 enter the element34 enter the element56 insertion & deletion from an array insert an element from an array delete an element from an array which case do u want to execute=1 INSERT AN ELEMENT which location u want to insert the element1 enter the element90 90 12 23 34 56 which case do u want to execute=2 DELETE AN ELEMENT which location u want to delete the element3 90 12 23 56 which case do u want to execute=3
17
SGHCMT
//WRITE A PROGRAM TO FIND THE SUM OF 2 MATRIX BY PASSING A 2-D ARRAY TO FUNCTION.
#include<iostream.h> #include<conio.h> #include <stdlib.h> void input(int a[][10],int m,int n); void read(int b[][10],int p,int q); void add(int a[][10],int b[][10],int c[][10],int m,int n); void output(int c[][10],int m,int n); void main() { int a[10][10],b[10][10],c[10][10],m,n,p,q; clrscr(); cout<<"how many rows and columnns in A matrix"; cin>>m>>n; cout<<"how many rows and columnns in B matrix"; cin>>p>>q; if((m!=p)&&(n!=q)) { cout<<"addition is not possible"; getch(); exit(0); } input(a,m,n); read(b,m,n); add(a,b,c,m,n); output(c,m,n); getch(); } void input(int a[][10],int m,int n) { int i,j; cout<<"input the rows & columns of 1st matrix="; for(i=0;i<m;i++) { for(j=0;j<n;j++) cin>>a[i][j]; } return; } void read(int b[][10],int p,int q) { int i,j; cout<<"input the rows & columns of 2nd matrix="; for(i=0;i<p;i++) 18 Manjot Kaur (524)
SGHCMT { for(j=0;j<q;j++) cin>>b[i][j]; } return; } void add(int a[][10],int b[][10],int c[][10],int m,int n) { int i,j; for(i=0;i<m;i++) { for(j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; } return; } void output(int c[][10],int m,int n) { int i,j; cout<<"\naddition is="; for(i=0;i<m;i++) { cout<<endl; for(j=0;j<n;j++) cout<<"\t"<<c[i][j]; } return; } /*cout<<"****output****"; how many rows and columnns in A matrix2 2 how many rows and columnns in B matrix2 2 input the rows & columns of 1st matrix=3 4 5 6 input the rows & columns of 2nd matrix=1 2 3 4 addition is= 4 8 6 10*/ 19 Manjot Kaur (524)
SGHCMT
20
SGHCMT
14//WRITE A PROGRAM TO DISPLAY THE EMPLOYEE DETAILS BY PASSING A STRUCTURE VARIABLE BY VALUE & THEN BY REERENCE TO A FUNCTION. 1)PASSED BY VALUE TO FUNCTION.
#include <iostream.h> #include <conio.h> struct employee { int emp_code; char emp_name[10]; int dept_code; double salary; }; void main() { clrscr(); void display(employee); employee emp1={512,"rahul",7,3612.3}; cout<<"employee details are:=\n"; display(emp1); getch(); } void display(employee e) { cout<<"employee code="<<e.emp_code; cout<<"\nname="<<e.emp_name; cout<<"\ndept. code="<<e.dept_code; cout<<"\nsalary="<<e.salary; return; } /******OUTPUT employee details are:= employee code=512 name=rahul dept. code=7 salary=3612.3 */
21
SGHCMT
SGHCMT
23
SGHCMT
24
25
SGHCMT
26
SGHCMT
SGHCMT
SGHCMT
24//WRITE A PROGRAM TO INPUT & DISPLAY THE DETAILS OF STUDENTS USING ARRAY OF OBJECTS.
#include<iostream.h> #include <conio.h> class student { private: char name[10]; int rolno; public: void input() { cout<<"enter name and rollno:"<<endl; cin>>name>>rolno; return; } void show() { cout<<"\nstudent record="; cout<<"name:"<<name<<endl<<"rolno"<<rolno<<endl; return; } }; void main() { clrscr(); int i,n; student s[10]; cout<<"\n how many students="; cin>>n; for(i=1;i<=n;i++) s[i].input(); for(i=1;i<=n;i++) { s[i].show(); } getch(); } /*******OUTPUT how many students=1 enter name and rollno: anshu 17 student record= name:anshu rolno 17 */ 29 Manjot Kaur (524)
SGHCMT
25//WRITE A PROGRAM TO SHOW THE USE O STATIC DATA MEMBERS & STATIC MEMBER FUNCTIONS.
#include <iostream.h> #include <conio.h> class account { int acc_no; double balance; static double rate; public: void read() { cout<<"input account number and balance->"; cin>>acc_no>>balance; } void show() { cout<<"\n account no="<<acc_no; cout<<"\ninterest="<<rate; cout<<"\nbalance="<<balance; } void qtr_rate_cal() { double interest=(balance*rate*0.25)/100; balance=balance+interest; } static void modify_rate(double incr) { rate=rate+incr; cout<<"\n modifying rate of interest="<<rate; } }; double account ::rate=0.05; void main() { clrscr(); account a1,a2; a1.read(); a2.read(); account::modify_rate(0.01); a1.qtr_rate_cal(); a2.qtr_rate_cal(); a1.show(); a2.show(); 30 Manjot Kaur (524)
SGHCMT getch(); } /*******OUTPUT input account number and balance->23 1000 input account number and balance->24 1200 modifying rate of interest=0.06 account no=23 interest=0.06 balance=1000.15 account no=24 interest=0.06 balance=1200.18
*/
31
SGHCMT
20//WRITE A PROGRAM TO SHOW THE USE OF VOID POINTER &THIS POINTER. 1)VOID POINTER
#include <iostream.h> #include <conio.h> void main() { clrscr(); void *p; int a=7; float b=12.5; p=&a; cout<<"a="<<*((int *)p)<<endl; p=&b; cout<<"b="<<*((float *)p)<<endl; getch(); } /* cout<<"***output***"; a=7 b=12.5*/
2)THIS POINTER #include <iostream.h> #include <conio.h> class rectangle { int l,b; public: void setdata(int i,int j) { cout<<"\naddress of object that generates setdata()all:"<<this<<"\n"; this->l=i; this->b=j; } void area() { cout<<"\naddress of object that generates setdata()all:"<<this<<"\n"; cout<<"area="<<this->l*this->b; } }; 32 Manjot Kaur (524)
SGHCMT void main() { rectangle r1; r1.setdata(10,15); r1.area(); getch(); } /*******OUTPUT address of object that generates setdata()all:0x8fc5fff2 address of object that generates setdata()all:0x8fc5fff2 area=150 */
33
SGHCMT
18//WRITE A PROGRAM TO CALCULATE THE AVERAGE O N NO.S OF AN ARRAY BY ALLOCATING & DEALLOCATING MEMORY DYNAMICALLY.
#include<iostream.h> #include<conio.h> #include<process.h> void main() { clrscr(); int *p; int n,sum=0; cout<<"neter how many elements="; cin>>n; p=new int[n];//allocates memory for n 'int'values dynamically i(p==null) if(p==NULL) { cout<<"memory allocation error"; exit(0); } for(int i=0;i<n;i++) { cout<<"enter value :"<<i+1<<"="; cin>>*(p+i); sum=sum+*(p+i); } float avg=float(sum)/n; cout<<"average o given value = "<<avg; delete[] p; getch(); } /*******OUTPUT neter how many elements=4 enter value :1=25 enter value :2=15 enter value :3=17 enter value :4=28 average of given value = 21.25
*/
34
SGHCMT }; void area:: display() { cout<<"\narea of rectangle=\n"<<l*b; return; } void main() { clrscr(); area r(6,4); r.display(); getch(); } /*******OUTPUT area of rectangle= 24 */ 3)COPY CTOR #include <iostream.h> #include <conio.h> class test { int a; public: test(int x) { a=x; } test(test &ob) { a=ob.a; } void display(); }; void test::display() { cout<<"\nvalue of a"<<a; return; } void main() { clrscr(); test t1(20); test t2(t1); t1.display(); t2.display(); getch(); 36 Manjot Kaur (524)
SGHCMT } /********OUTPUT value of a=20 value of a=20 */ 4)DYNAMIC CTOR #include <iostream.h> #include <conio.h> class height { int feet; double inches; public: height(int f) { feet=f; inches=0.0; } height( double f) { feet=int(f); inches=(f-int(f))*12.0; } height() { feet=inches=0; } height(int f,double in) { feet=f; inches=in; } void show() { cout<<"Feet="<<feet<<"inches="<<inches<<"\n"; } }; void main() { clrscr(); height h1,h2,h3; h1=height(5); h2=height(5.5); h3=height(5.8); h1.show(); h2.show(); 37
SGHCMT h3.show(); getch(); } /******OUTPUT Feet=5inches=0 Feet=5inches=6 Feet=5inches=9.6 */ 5)MULTIPLE CTOR #include <iostream.h> #include <conio.h> class area { int l,b; public: area(int a) { l=4; b=a; } area(int m,int n) { l=m; b=n; } void cal(); }; void area::cal() { cout<<"\narea is="<<l*b; } void main() { clrscr(); area a2(5); area a3(6,9); a1.cal(); a2.cal(); a3.cal(); getch(); } /******OUTPUT area is=20 area is=54 */
38
SGHCMT
SGHCMT getch(); } /*******OUTPUT input roll no & name=524 money input the date of birth =1-12-1989 roll no=524 name money date=1 month=12 year=1989 */
40
SGHCMT
29//WRITE A PROGRAM TO SHOW THE USE OF FRIEND FUNTION & FRIEND CLASSES.
1)FRIEND FUNCTION /*#include <iostream.h> #include <conio.h> class test { int a; public: test(int x) { a=x; } friend void display(test t1); }; void display(test t1) { cout<<"value of a->"<<t1.a; } void main() { clrscr(); test t(5); display(t); getch(); } /*******OUTPUT value of a->5 */
//FRIEND CLASSES #include<iostream.h> #include <conio.h> class xxx { int x,y; public: xxx(int xx,int yy) { x=xx; 41 Manjot Kaur (524)
SGHCMT y=yy; } friend class yyy; }; class yyy { public: void f1(xxx objx) { cout<<"\nx="<<objx.x; } void f2(xxx objy) { cout<<"\ny="<<objy.y; } }; void main() { xxx ob1(10,15); yyy ob2; ob2.f1(ob1); ob2.f2(ob1); getch(); } /*******OUTPUT x=10 y=15 x=10 y=15
*/
42
SGHCMT
//WRITE A PROGRAM TO ADD 2 COMPLEX NO.S USING CONSTRUCTORS & ALSO SHOW THE WORKING OF DESTRUCTOR.
#include<iostream.h> #include<conio.h> class complex { private: int x,y,a,b,z,w; public: complex() { a=b=x=y=11; } complex(int c) { x=y=c; } complex (int m, int n) { a=m; b=n; } void add_disp(complex c1,complex c2) { z=c1.x+c2.a; w=c1.y+c2.b; cout<<endl<<"sum is "<<z<<" + "<<w<<"i"; } ~complex() { cout<<"\ndistructor invoked"<<z<<"+ "<<w<<"i"; } }; //end of class void main() { complex c1(28); complex c2(31,17); complex c3; c3.add_disp(c1,c2); getch(); } /********OUTPUT sum is 59 + 45i distructor invoked-14+ 10177i distructor invoked0+ 8105i */ 43 Manjot Kaur (524)
SGHCMT
SGHCMT for(i=0;i<n;i++) cout<<a[i]<<"\n"; break; } case 2: { cout<<"enter the position from where the element is to be deleted="; cin>>pos; fsor(i=pos-1;i<=n;i++) strcpy(a[i],a[i+1]); n--; cout<<"\n elements are="; for(i=0;i<n;i++) cout<<a[i]<<"\n"; } } }while(z<3); getch(); } /*******OUTPUT how many no. of strings=2 enter the strings money enter the strings sheenu insertion & deletion from an array of strings insert an element from an array of string delete an element from an array of string which case do u want to execute=1 enter the position where u want insert=1 enter d string to insert=rajni elements are=money rajni sheenu which case do u want to execute=3 */
45
SGHCMT
SGHCMT { child x; clrscr(); x.childin(); x.childout(); getch(); } /*********OUTPUT ENTER ROLL NUMBER OF A STUDENT:- 507 ENTER NAME OF A STUDENT:sudesh ENTER AGE OF A STUDENT:19 ENTER MARKS OF A STUDENT:85 ------INFORMATION OF A STUDENT-----ROLL NUMBER OF A STUDENT:- 507 NAME OF A STUDENT:sudesh AGE OF A STUDENT:19 MARKS OF A STUDENT:85 2)MULTIPLE INHERITANCE #include<iostream.h> #include<conio.h> class student { int roll_no; char name[20]; public: void getdata() { cout<<"ENTER ROLL NUMBER OF A STUDENT:- "; cin>>roll_no; cout<<"ENTER NAME OF A STUDENT:"; cin>>name; } void display() { cout<<"\n\t\t\t"<<"------INFORMATION OF STUDENT-----"<<endl<<endl; cout<<"ROLL NUMBER OF A STUDENT:- "<<roll_no<<endl; cout<<"NAME OF A STUDENT:"<<name<<endl; } }; class sports { char game[20]; public: Manjot Kaur 47 (524)
SGHCMT void getgame() { cout<<"ENTER THE NAME OF GAME:"; cin>>game; } void putgame() { cout<<"THE NAME OF GAME:"<<game<<endl; } }; class test:public student,public sports { int sub1,sub2; public: void readdata(); void putdata(); }; void test::readdata() { getdata(); cout<<"ENTER MARKS OF THE SUBJECT 1:- "; cin>>sub1; cout<<"ENTER MARKS OF THE SUBJECT 2:- "; cin>>sub2; getgame(); } void test::putdata() { display(); cout<<"MARKS OF SUBJECT 1:"<<sub1<<endl; cout<<"MARKS OF SUBJECT 2:"<<sub2<<endl; putgame(); } void main() { test x; clrscr(); x.readdata(); x.putdata(); getch(); } /*********OUTPUT ENTER ROLL NUMBER OF A STUDENT:- 23 ENTER NAME OF A STUDENT:money ENTER MARKS OF THE SUBJECT 1:- 67 ENTER MARKS OF THE SUBJECT 2:- 78 ENTER THE NAME OF GAME:cricket 48
SGHCMT ------INFORMATION OF STUDENT----ROLL NUMBER OF A STUDENT:- 23 NAME OF A STUDENT:money MARKS OF SUBJECT 1:67 MARKS OF SUBJECT 2:78 THE NAME OF GAME:cricket 31
*/
3)MULTILEVEL INHERITANCE
#include<iostream.h> #include<conio.h> class student { int roll_no; char name[25]; public: void getdata() { cout<<"ENTER ROLL NUMBER OF A STUDENT:- "; cin>>roll_no; cout<<"ENTER NAME OF A STUDENT:"; cin>>name; } void dataout() { cout<<"\n\t\t\t"<<"------INFORMATION OF A STUDENT------"<<endl<<endl; cout<<"ROLL NUMBER OF A STUDENT:- "<<roll_no<<endl; cout<<"NAME OF A STUDENT:"<<name<<endl; } }; class test:public student { protected: int sub1,sub2; public: void readdata() { getdata(); cout<<"ENTER MARKS OF THE SUBJECT 1:- "; cin>>sub1; cout<<"ENTER MARKS OF THE SUBJECT 2:- "; cin>>sub2; } Manjot Kaur 49 (524)
SGHCMT void putdata() { dataout(); cout<<"MARKS OF SUBJECT 1:cout<<"MARKS OF SUBJECT 2:} }; class total:public test { int total; public: void compute() { total=sub1+sub2; cout<<"TOTAL MARKS:} }; void main() { total x; clrscr(); x.readdata(); x.putdata(); x.compute(); getch(); } /*********OUTPUT ENTER ROLL NUMBER OF A STUDENT:- 507 ENTER NAME OF A STUDENT:sudesh ENTER MARKS OF THE SUBJECT 1:- 87 ENTER MARKS OF THE SUBJECT 2:- 75 ------INFORMATION OF A STUDENT-----ROLL NUMBER OF A STUDENT:- 507 NAME OF A STUDENT:sudesh MARKS OF SUBJECT 1:87 MARKS OF SUBJECT 2:75 TOTAL MARKS:162
"<<sub1<<endl; "<<sub2<<endl;
"<<total;
50
SGHCMT //HIERARCHIAL INHRITANCE #include<iostream.h> #include<conio.h> class student { int roll_no; char name[25]; public: void getdata() { cout<<"ENTER ROLL NUMBER OF A STUDENT:- "; cin>>roll_no; cout<<"ENTER NAME OF A STUDENT:"; cin>>name; } void display() { cout<<"\n\t\t\t"<<"------INFORMATION OF A STUDENT------"<<endl<<endl; cout<<"ROLL NUMBER OF A STUDENT:- "<<roll_no<<endl; cout<<"NAME OF A STUDENT:"<<name<<endl; } }; class bsc:public student { int sub1,sub2,sub3; public: void readdata() { getdata(); cout<<"ENTER MARKS OF THE SUBJECT 1:- "; cin>>sub1; cout<<"ENTER MARKS OF THE SUBJECT 2:- "; cin>>sub2; cout<<"ENTER MARKS OF THE SUBJECT 3:- "; cin>>sub3; } void putdata() { display() cout<<"MARKS OF SUBJECT 1:- "<<sub1<<endl; cout<<"MARKS OF SUBJECT 2:- "<<sub2<<endl; cout<<"MARKS OF SUBJECT 3:- "<<sub3<<endl; } }; class bcom:public student Manjot Kaur 51 (524)
SGHCMT { int sub1,sub2,sub3,sub4,sub5; public: void readdata() { cout<<"\n\t\t\t"<<"------INFORMATION OF SECOND STUDENT------"<<endl<<endl; getdata(); cout<<"ENTER MARKS OF THE SUBJECT 1:- "; cin>>sub1; cout<<"ENTER MARKS OF THE SUBJECT 2:- "; cin>>sub2; cout<<"ENTER MARKS OF THE SUBJECT 3:- "; cin>>sub3; cout<<"ENTER MARKS OF THE SUBJECT 4:- "; cin>>sub4; cout<<"ENTER MARKS OF THE SUBJECT 5:- "; cin>>sub5; } void putdata() { display(); cout<<"MARKS OF SUBJECT 1:"<<sub1<<endl; cout<<"MARKS OF SUBJECT 2:"<<sub2<<endl; cout<<"MARKS OF SUBJECT 3:"<<sub3<<endl; cout<<"MARKS OF SUBJECT 4:"<<sub4<<endl; cout<<"MARKS OF SUBJECT 5:"<<sub5<<endl; } }; void main() { bsc x; bcom y; clrscr(); x.readdata(); x.putdata(); y.readdata(); y.putdata(); getch(); }
52
SGHCMT
/*********OUTPUT*********** ENTER ROLL NUMBER OF A STUDENT:- 507 ENTER NAME OF A STUDENT:sudesh ENTER MARKS OF THE SUBJECT 1:- 64 ENTER MARKS OF THE SUBJECT 2:- 75 ENTER MARKS OF THE SUBJECT 3:- 54 ------INFORMATION OF A STUDENT-----ROLL NUMBER OF A STUDENT:- 507 NAME OF A STUDENT:sudesh MARKS OF SUBJECT 1:64 MARKS OF SUBJECT 2:75 MARKS OF SUBJECT 3:54 ------INFORMATION OF SECOND STUDENT-----ENTER ROLL NUMBER OF A STUDENT:- 284 ENTER NAME OF A STUDENT:sudesh ENTER MARKS OF THE SUBJECT 1:- 75 ENTER MARKS OF THE SUBJECT 2:- 64 ENTER MARKS OF THE SUBJECT 3:- 85 ENTER MARKS OF THE SUBJECT 4:- 75 ENTER MARKS OF THE SUBJECT 5:- 86 ------INFORMATION OF A STUDENT-----ROLL NUMBER OF A STUDENT:- 284 NAME OF A STUDENT:sudesh MARKS OF SUBJECT 1:75 MARKS OF SUBJECT 2:64 MARKS OF SUBJECT 3:85 MARKS OF SUBJECT 4:75 MARKS OF SUBJECT 5:86 */
53
SGHCMT //HYBRID INHERITANCE #include <iostream.h> #include <conio.h> class student { protected: int rno; public: void get_no(int); void put_no(); }; void student::get_no(int x) { rno=x; } void student::put_no() { cout<<"roll no="<<rno; } class test:public student { protected: int part1,part2; public: void get_marks(int,int); void put_marks(); }; void test ::get_marks(int a,int b) { part1=a; part2=b; } void test::put_marks() { cout<<"\nmarks obtained="<<part1<<"\t"<<part2; } class sport { protected: int score; public: void get_score(int); void put_score(); }; void sport::get_score(int m) 54
SGHCMT { score=m; } void sport::put_score() { cout<<"\nscore is="<<score; } class report:public test,public sport { public: int result1; void result(); }; void report::result() { result1=part1+part2+score; put_no(); put_marks(); put_score(); cout<<"\ntotal"<<result1; } void main() { clrscr(); report r; r.get_no(3); r.get_marks(40,50); r.get_score(45); r.result(); getch(); } /******OUTPUT roll no=3 marks obtained=40 score is=45 total 135 */ 50
55
SGHCMT
SGHCMT student s1; s1.read(); cout<<"displaying student information"; s1.show(); getch(); } /*********OUTPUT enter name and phno= bhanu 567 enter rollno and course= 1 bca displaying student information name=bhanu phone no=567 rollno=1 course=bca */
57
SGHCMT
SGHCMT void main() { clrscr(); gamma g(5,2.5,2,3); cout<<endl; g.show_x(); g.show_y(); g.show_mn(); getch(); } /********OUTPUT Beta initialized Alpha initialized Gamma initialized x =5 y = 2.5 m= 2 n= 3 */
59
SGHCMT
4//WRITE A PROGRAM TO SHOW THE USE OF MANIPULATER (SETW,SETFILL,SETWIDTH,HEX,DEC,OCT,SET PRECISION)USING INLINE FUCTION.
#include<iostream.h> #include<conio.h> #include<iomanip.h> inline void setfil() { int n=17; float f=90.8345; cout<<"n="<<setw(11)<<setfill('#')<<n<<endl; cout<<"float="<<setprecision(2)<<setfill('~')<<f; } inline void setw() { int age=34; char a='x'; float f=89.1; cout<<"age is"<<setw(5)<<age<<endl; cout<<"character is "<<setw(4)<<a<<endl; cout<<"f is "<<setw(4)<<f<<endl; } inline void setbase() { int n,n1,n2; cout<<"enter n="; cin>>n; cout<<"enter n1="; cin>>hex>>n1; cout<<"enter n2="; cin>>oct>>n2; cout<<"hexadecimal eqivalent="<<hex<<n<<endl; cout<<"decimal equivalent="<<dec<<n<<endl; cout<<"octal equivalent="<<oct<<n<<endl; cout<<"hexadecimal eqivalent="<<hex<<n1<<endl; cout<<"decimal equivalent="<<dec<<n1<<endl; cout<<"octal equivalent="<<oct<<n1<<endl; cout<<"hexadecimal eqivalent="<<hex<<n2<<endl; cout<<"decimal equivalent="<<dec<<n2<<endl; cout<<"octal equivalent="<<oct<<n2<<endl; } 60 Manjot Kaur (524)
SGHCMT void main() { clrscr(); setfil(); setw(); setbase(); getch(); } /*********OUTPUT n=#########17 float=90.83age is~~~34 character is x f is 89.1 enter n=2 enter n1=1 enter n2=3 hexadecimal eqivalent=2 decimal equivalent=2 octal equivalent=2 hexadecimal eqivalent=1 decimal equivalent=1 octal equivalent=1 hexadecimal eqivalent=3 decimal equivalent=3 octal equivalent=3 */
61
SGHCMT
10//WRITE A PROGRAM TO CREATE A FUNCTION pow() TO RAISE A NO. N TO POWER N.USE THE CONCEPT OF FUNCTION OVERLODING TO CALCULATE 5(3),N(3),N(N).
#include<iostream.h> #include<conio.h> void main() { int i,n,p=1; clrscr(); for(i=1;i<=3;i++) p=p*5; cout<<"value of 5 raise to power 3="<<p; cout<<endl<<"enter value of n="; cin>>n; p=1; for(i=1;i<=3;i++) p=p*n; cout<<"value of n raise to power 3="<<p; p=1; for(i=1;i<=n;i++) p=p*n; cout<<endl<<"value of n raise to power n="<<p; getch(); } /******output**** value of 5 raise to power 3=125 enter value of n=3 value of n raise to power 3=27 value of n raise to power n=27*/
62
SGHCMT
*/
63
SGHCMT
64