Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. wap to print welcome? 2. wap to print the addition , subtraction, multiplication and division of any given noi. using function? 3.wap to calculate simple interest? 4. wap to find out the greatest no. among given three no.s ? . wap to chech wheather the no is prime or not? !. wapo to print table of any given no. ? ". wap to calculate the factorial of given no. using while and do while loop? #. $ $$ $$$ $$$$ $$$ $$ $ %. &'()*)('& &'() )('& &'( &' & ('& '& &
1+. ,&- ./ 0/1. .2* 3/ I3 &11&4? 11. wap for the addition of two matrices? 12. wap for multiplication of matrices? 13. wap to count the length of given string? 14. wap to print the reverse of string? 1 . wap to chec5 wheather the given string is palandram or not? 1!. wap to calculate area of circle, rectangle, s6uare using polymorphism ? 1". wap to implement a multiple inheritance?
Q1.wap
to print welcome
/ut put
,elcome 7
#include<iostream.h> #include<conio.h> class a c ! "loat a, # $u lic% &oid 'etnum("loat n,"loat m) ! a*n# *m# + &oid $utnum(&oid) ! cout<<,-Irst no is%,<<a# cout<<,Second no is%,<< <<,.n,# + &oid sum("loat /,"loat 0) ! "loat 1# 1*/20# cout<< ,.nSUM IS%,<<1# + &oid di"("loat /,"loat 0) ! "loat $# $*/30# cout<<,.nDi""erence is%,<<$# + &oid mul("loat /,"loat 0) ! "loat 4# 4*/*0# cout<<,.nMulti$lication is%,<<4# + &oid di&("loat /,"loat 0) !
"loat r# r*//0# cout<<,.nDi&ision is%,<<r# + +# "loat main() ! a c a5,a6# clrscr()# a5.'etnum(6,7)# a6.sum(6,7)# a6.di"(6,7)# a6.di&(6,7)# a6.mul(6,7)# return(8)# +
Out put
Sum is :5 Difference is :-1 Division is :0.66666 !u"tip"ication is :6#
#include<iostream. h> #include<conio. > &oid main ( ) ! clrscr ( )# "loat $, r. t. SI# cout<<9enter the $rinc i$al &alue9# cin>>$# cout<<9enter the rate9# cin>>r# cout<<9enter the time9# cin>>t# SI*$*r*t/588# cout>>%9<<SI# 'etch ( )# !
O$T%$T
enter the $rinci$al &alue%:: enter 7rd num er;; the 7rd num er is 'reatest
Q. 4 Write a program to print which number is greater between 3 input numbers by outside class. Sol:// Prog. of greater number by class
#include<iostream.h> #include<conio.h> class greator { private: int a,b,c; public: void input void!; void print void!; "; void greator::input void! { cout<<# enter value of a$#; cin>>a; cout<<# enter value of b$#; cin>>b;
cout<<# enter value of c$#; cin>>c; " void greator::print void! { if a>b %% a>c! cout<<# a is greator#; if b>a %% b>c! cout<<# b is greator#; if c>a %% c>b! cout<<# c is greator#; " void main ! { clrscr !; greator &; &.input !; &.print !; "
/ut put
enter the value of a$ ' enter the value of b$ ( enter the value of c$ ) b is greater*
/9.-9.
enter the no. you -ant to chec+ :1( no. is prime enter the no. you -ant to chec+:) no. is not prime
Out put
enter the num er 7 7 > ? 56 5: 5; 65 6@ 6A 78B
#include<iostream.h> #include<conio.h> &oid main() ! clrscr()# int n,"# "*5# cout<<,Cnter the the num er,# cin>>n# =hile(n>*5) ! "*"*n# n33# + cout<<,the "actorial is,<<"#
'etch()# +
Output
enter t1e num0er 5 factoria" is 120#
8.#.
2 2 2 2 2 2 2 2 22 222 22 2
!rint"("#nter num$er o" ro%s\n"); scan"("&d",'n); "or ( c ( ) ; c <( n ; c**) { "or ( ( ) ; <( c ; ** ) !rint"("+"); } !rint"("\n");
return .;
Out put
8%. -1I3. .2I0 0*1I*0 :; &'()*)('& &'() &'( &' & )('& ('& '& &
#include<iostream.h> #include<conio.h> void main ! { clrscr !; int i,3,+,s; char a $ 456 ; for i$1;3<$';i//! { for s$7;s>$i;s88! { cout<< 9 : ; " for 3$1;3<$i;388! {
cout<<a; a//; " a//; for +$1;+<$i81;+//! { a88; cout<<a; " cout<<endl; " cout<<endl; "
/9.-9.
/utput
8 11 ,rie a program for addion of two matrices and display their sum in third matrix.
include<iostream.h> #include<conio.h> &oid main( ) ! int aD7E D7E , D7E D7E,cD7ED7E,i,F,G# clrscr()# cout<<HHenter element o" 5st matri/9# "or(i*8#i<7#i22) ! "or(F*8#F<7#F22) ! cin>>aDiEDiE# + ! cout<<HHenter element o" 6nd matri/9# "or(i*8#i<7#i22) ! "or(F*8#<7#F22) ! cin>> DiEDFE# + + "or(i*8#i<7#i22) ! "or(F*8#F<7#F22) !
Output
enter the elements o" 5st matri/ ? ; A > : @ 7 6 5 enter the el#ements o" 6ndmatri/ 5 6 7 @ : > A ; ? Ihe sum o" matri/es is 585858585858585858B
Q 12 &)% to fin/ t1e mu"tip"ication of two matrices. #include<stdio.h> #include<conio.h> &oid main() ! int aD58ED58E, D58ED58E,cD58ED58E,m,n,i,F,l,G# clrscr()# $rint"(,Cnter order o" the matri/ A %.n,)# scan"(,JdJd,,Km,Kn)# $rint"(,Cnter the elements o" the matri/ A %.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<n#F22) ! scan"(,Jd,,KaDiEDFE)# + + $rint"(,Matri/ A %.n.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<n#F22) ! $rint"(,Jd.t,,aDiEDFE)# + $rint"(,.n,)# + $rint"(,Cnter order o" the matri/ B %.n,)# scan"(,JdJd,,Kn,Kl)# $rint"(,Cnter the elements o" the matri/ B %.n,)# "or(i*8#i<n#i22) ! "or(F*8#F<l#F22) ! scan"(,Jd,,K DiEDFE)# + + $rint"(,Matri/ B %.n.n,)# "or(i*8#i<n#i22) !
"or(F*8#F<l#F22) ! $rint"(,Jd.t,, DiEDFE)# + $rint"(,.n,)# + $rint"(,Multi$lication o" the matri/ A and B %.n.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<l#F22) ! cDiEDFE*8# "or(G*8#G<n#G22) ! cDiEDFE*cDiEDFE2aDiEDGE* DGEDFE# + $rint"(,Jd.t,,cDiEDFE)# + $rint"(,.n,)# + 'etch()# +
Output :
enter order o" the matri/ A % 6 7 enter the elements o" the matri/ A % 6 7 6 7 @ 5 matri/ A % 6 7 6 7 @ 5 enter order o" the matri/ B % 7 6 enter the elements o" the matri/ B % 5 6 @ 7 5 6 matri/ B % 5 6 @ 7 5 6 multi$lication o" the matri/ A and B % 5> 5A 68 68B
Q.13Write to create function of calculate length of string. Sol://Prog. of length of string function
#include<iostream.h> #include<conio.h> int len char n<',=!; void main ! { clrscr !; char &<',=; int l; cout<<#enter string#; cin>>&; l$len &!; cout<<l; " int len char n<',=!; { int i$l; -hile n<i=>$?@,?! { i//; " return i!;
enter strin/0cric et 12
Q14 Write to print reverse string without using function. Sol://Prog. of reverse sttring
#include<iostream.h> #include<conio.h> void main ! { clrscr !; char n<',=; int l$1,r; cout<<#enter string:#; cin>>n; -hile n<1=>$?@,?! { l//; " for r$1;r>$,;r88! { cout<<n<r=; " "
Lut $ut
Output :
DEuare ! { a$,; " DEuare float &! { a$&; " float 5rea ! { return a2a; " " class Fect { float l,b; Fect ! { l$,; b$,; " Fect float &, float y! { l$&; b$y; " float 5rea ! { return l2b; " " void main ! { clrscr !; Briangle t1 .,7!; cout << #5rea of triangle is # << t1.5rea !; ;ircle c 7!; cout << #5rea of circle is # << c.5rea !; DEuare s '!; cout << #5rea of DEuare is # << s.5rea !; Fect r C,)! cout << #5rea of Fectangle is# << r.5rea !; getch !; "
/ut put
area of triang"e: 3 area of circ"e : 50.23 area of s4uare: 25 area of rectang"e: 15#
#include <iostream.h> #include<conio.h> class 5 " public: void f1 ! { cout<<:f1 in 5:<<endl; " ";class G " public: void f. ! { cout<<:f. in G:<<endl; " 9; class ;:public 5,public G { public: void fC ! cout<<:fC in ;:<<endl; "
/9.-9.
f1 in 5 f. in G fC in ;
S$9!ITT(D 9:
*)'*I D)S,O')
Dept of .+S