1. The document appears to be a computer science project submission containing 21 programs written by Rahul Kumar Sharma.
2. The programs cover a range of introductory concepts like input/output, if/else statements, functions, operators, and basic math/stat calculations.
3. Each program is accompanied by its source code and output to demonstrate the code's functionality.
1. The document appears to be a computer science project submission containing 21 programs written by Rahul Kumar Sharma.
2. The programs cover a range of introductory concepts like input/output, if/else statements, functions, operators, and basic math/stat calculations.
3. Each program is accompanied by its source code and output to demonstrate the code's functionality.
1. The document appears to be a computer science project submission containing 21 programs written by Rahul Kumar Sharma.
2. The programs cover a range of introductory concepts like input/output, if/else statements, functions, operators, and basic math/stat calculations.
3. Each program is accompanied by its source code and output to demonstrate the code's functionality.
Grade Sign. 01. Program to print your name, class and roll no. on the screen. 4-4
02. Program that inputs a students marks in three subjects (out of 100) and prints the percentage marks. 4-5
03. Program that accepts radius of a circle and print its area. 5-6
04. Program (using a function) to accept a number and print its cube. 6-7
05. Program that accepts a character between a to j and prints next 4 characters. 7-8
06. Program to chain multiple assignments (as many as possible). 8-9
07. The value of e is known to be 2.71828... Using this value, write a program to determine the value of this expression: 2-ye 2y +4y. Obtain value of y from the user. 9-10
08. Program that reads in a character <char> from the keyboard and then displays one of the following messages: (i) if <char> is a lower case letter, the message the upper case character corresponding to <char> is, (ii) if <char> is an uppercase letter, the message The lower case character corresponding to <char> is, (iii)if <char> is not a letter, the message <char> is not a letter. 10-12
09. Temperature-conversion program that gives the user the option for converting Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon users choice carries out the conversion. 12-13
3
10. Program to accept three integers and print the largest of the three. Making use of if statement. 14-15
11. Program to create the equivalent of four- function calculator. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetical operation: addition, subtraction, multiplication or division of the two numbers. Finally, it displays the result. 15-16
12. Program to calculate commission for salesmen. The commission is calculated according to given rates. 17-19
13. Program to calculate and print roots of a quadratic equation ax 2 +bx+c. 19-21
14. Program to calculate the factorial of an integer. 21-22
15. Program to show handicap of call by value method. 22-24
16. Program to swap two values. 24-26
17. Program to add two matrices. 26-29
18. Program to illustrate passing of structure by value. 29-31
19. Program to illustrate passing of structure by reference. 31-34
20. Program to find row sum and column sum of matrix. 34-36
21. Program to multiply two matrices. 36-39
4
Program-1: Program to print your name, class and roll no. on the screen. #include<iostream.h> #include<conio.h> //for clear screen function clrscr() Int main() { Clrscr(); Cout<<Name-Rahul Sharma<<\n<<class-11 D<<\n<<Roll. No.- 26; return 0; }
Program 2: Program that inputs a students marks in three subjects (out of 100) and prints the percentage marks. #include,iostream.h> #include<stdlib.h> Int main() { 5
System (cls); float sub1,sub2,sub3,marks,perc; cout<<enter marks obtained in 3 subjects:; cin>>sub1>>sub2>>sub3; Marks=sub1+sub2+sub3; Perc=(marks/300)*100; Cout<<\n<<the percentage marks are:<<perc<<%; return 0; }
Program 3: Program that accepts radius of a circle and print its area. #include<iostream.h> #include<conio.h> Int main() { clrscr(); float radius,area; 6
cout<<enter the radius of the circle:; cin>>radius; area=3.14*radius*radius; Cout<<area=<<area; getch(); return 0; }
Program 4: Program (using a function) to accept a number and print its cube. #include<iostream.h> #include<stdlib.h> Float cube(float); Int main() { System (cls); float num; cout<<enter a number:; 7
cin>>num; cout<<\n<<the cube of<<num<<is<<cube(num)<<\n; return 0; } float cube(float a) { return a*a*a; } Program 5: Program that accepts a character between a to j and prints next 4 characters. #include<iostream.h> Int main() { Char ch,ch1,ch2,ch3,ch4; Cout<<enter a character between a and j:; Cin>>ch; Int num=ch; Ch1=ch+1; 8
Ch2=ch+2 Ch3=ch+3; Ch4=ch+4; cout<<\n next four characters are:; cout<<\n<<ch1<<\n<<ch2<<\n<<ch3<<\n<<ch4<<\n ; return 0; }
Program 6: Program to chain multiple assignments (as many as possible). #include<iostream.h> Int main() { Int a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; Int a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1; Int r1,s1,t1,u1,vi,w1,x1,y1,z1; Int a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2; 9
Int r2,s2,t2,u2,v2,w2,x2,y2,z2; a=b=c=d=e=f=g=h=i=j=k=l=m=n=0 =p=q=r=s=t=u=v=w=x=y=z =a1=b1=c1=d1=e1=f1=g1=h1=i1=j1=k1=l1=m1=n1=o1=p1=q1 =r1=s1=t1=u1=v1=w1=x1=y1=z1=a2=b2=c2=d2=e2=f2=g2=h2 =i2=j2=k2=l2=m2=n2=o2=p2=q2=r2=10; cout<<a; return 0; } The above program produces result as follows: 10
Program7: The value of e is known to be 2.71828... Using this value, write a program to determine the value of this expression: 2-ye 2y +4y. Obtain value of y from the user. #include<iostream.h> #include<math.h> Int main() 10
{ const double e=2.71828; double result,y; cout<<enter value of y:; cin>>y; result=2-y*exp(2*y)+pow(4,y); cout<<the result of the given expression is:<<result; return 0; }
Program 8: Program that reads in a character <char> from the keyboard and then displays one of the following messages: (i) if <char> is a lower case letter, the message the upper case character corresponding to <char> is, (ii) if <char> is an uppercase letter, the message The lower case character corresponding to <char> is, (iii)if <char> is not a letter, the message <char> is not a letter. #include<iostream.h> 11
#include<conio.h> #include<stdio.h> Int main() { clrscr(); char ch; cout<<enter character:; cin>>ch; Int code=ch; If(code>=97 && code<=122) { cout<<The upper case character corresponding to <<ch<<is:<<(char)(code-32); } If(code>=65 && code<=90) { cout<<The lower case character corresponding to<<ch<<is:<<(char)(code+32); } 12
If((code<65 II code>90) && (code<97 II code>122)) { cout<<The<<<<ch<<is not a letter; } getch(); }
Program 9: Temperature-conversion program that gives the user the option for converting Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon users choice carries out the conversion. #include<iostream.h> Int main() { Int choice; double temp,conv_temp; cout<<temperature conversion menu<<\n; cout<<1.fahrenheit to Celsius<<\n; cout<<2.celsius to Fahrenheit<<\n; 13
cout<<enter your choice(1-2):; cin>>choice; If(choice==1) { cout<<\n<<enter temperature in Fahrenheit:; cin>>temp; conv_temp=(temp-31)/1.8; cout<<the temperature in Celsius is<<conv_temp<<\n;
else { cout<<\n<<enter temperature in Celsius:; cin>>temp; conv_temp=(1.8*temp)+32; cout<<the temprature in Fahrenheitis<<conv_temp<<\n; } return 0; } 14
Program 10: Program to accept three integers and print the largest of the three. Making use of if statement. #include<iostream.h> Int main() { Int x,y,z,max; cout<<enter three numbers:; cin>>x>>y>>z; max=x; If(y>max) max=y; If(z>max) max=z; cout<<\n<<the largest of<<x<<,<<y<<,<<and<<z<<is<<max; return 0; } Output- 15
Enter three numbers : 3 5 6 The largest of 3, 5 and 6 is 6
Program 11: Program to create the equivalent of four- function calculator. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetical operation: addition, subtraction, multiplication or division of the two numbers. Finally, it displays the result. #include<iostream.h> Int main() { char ch; float a,b,result; cout<<enter two numbers:; cin>>a>>b; cout<<enter the operator(+,-,*,/):; cin>>ch; cout<<\n; 16
Program 12: Program to calculate commission for salesmen. The commission is calculated according to given rates. Sales Commission Rate 3001 onwards 15% 22001-30000 10% 12001-22000 7% 5001-12000 3% 0-5000 0% #include<iostream.h> Int main() { float sales,comm; cout<<enter sales made by the salesman:; cin>>sales; If(sales>5000) If(sales>12000) If(sales>22000) If(sales>30000) comm=sales*0.15; 18
Output- Enter sales made by the salesman:20000 The commission is:1400 Enter sales made by the salesman:25000 The commission is:2500 Enter sales made by the salesman:33000 19
The commission is:4950
Program 13: Program to calculate and print roots of a quadratic equation ax 2 +bx+c. #include<iostream.h> #include<math.h> Int main() { float a,b,c,root1,root2,delta; cout<<enter three numbers a,b&c of <<ax^2+bx+c:\n; cin>>a>>b>>c; If(!a) cout<<value of \a\ should not be zero <<\n Aborting!!!<<\n; else { delta=b*b-4*a*c; 20
If(delta>0) { root1=(-b+sqrt(delta))/(2*a); root2=(-b-sqrt(delta))/(2*a); cout<<roots are real and unequal<<\n; cout<<root1=<<root1 <<root2=<<root2<<\n; } else if(delta==0) { root1=-b/(2*a); cout<<roots are real and equal<<\n; cout<<root1=<<root1; cout<<root2=<<root1<<\n; } else cout<<roots are complex and imaginary<<\n; } 21
return 0; }
Output- Enter three numbers a,b&c of ax^2+bx+c: 2 3 4 Roots are complex and imaginary Program 14: Program to calculate the factorial of an integer. #include<iostream.> #include<stdlib.h> Int main() { System(cls); Int I,num,fact=1; cout<<\nEnter integer:; cin>>num; I=num; 22
a=7, b=4 The swapped values are: a=4, b=7 The values after swap() are: a=4, b=7
Program17: Program to add two matrices. #include<iostream.h> #include<process.h> Int main() { Int a[10][10], b[10][10], c[10][10]; Int I,j,m,n,p,q; cout<<\nInput row and column of matrix-A\n; cin>>m>>n; cout<<\nInput row and column of matrix-B\n; cin>>p>>q; 27
If((m==p)&&(n==q)) cout<<Matrix can be added\n; else { cout<<Matrix cannot be adde\n; exit(0); } cout<<\nInput matrix-A\n; for(i=0;i<m;i++) { for(j=0;j,n;j++) cin>>a[i][j]; } cout<<\nMATRIX-A:; for(i=0;i<m;i++) { cout<<\n; for(j=0;j<n;j++) 28
cout<<<<a*i+*j+; } cout<<\nInput matrix-B\n; for(i=0;i<p;i++) { cout<<\n; for(j=0;j<q;j++) cout<<<<b*i+*j+; } for(i=0;i<m;i++) { for(j=0;j<n;j++) c[i][j]=a[i][j]+b[i][j]; } cout<<\nThe sum of two matrix is:\n; for(i=0;i<m;i++) { cout<<\n; 29
for(j=0;j<n;j++) cout<<<<c*i+*j+; } return 0; }
Program 18: Program to illustrate passing of structure by value. #include<iostream.h> Struct Distance { Int feet; Int inches; }; Int main() { Distance length1,length2; void prnsum(Distance l1,Distancel2); 30
Enter length2 : Feet : 4 Inches : 5 Total Feet : 8 Total Inches : 4
Program 20: Program to find row sum and column sum of matrix. #include<iostream.h> Int main() { Int A[10][10],I,j,r[10],c[10],row,col; cout<<\nEnter the number of rows and columns of matrix:; cin>>row>>col; cout<<\nEnter the elements of a matrix:\n; for(i=0;i<row;++i) for(j=0;j<col;++j) cin>>A[i][j]; 35
} for(i=0;i<row;++i) cout<<\nsSum of row#<<i+1<<is:<<r*i+; for(i=0;i<col;++i) cout<<\nSum of column#<<i+1<<is:<<c*i+; return 0; }
Program:21Program to multiply two matrices. #include<iostream.h> #include<process.h> Int main() { Int A[10][10], B[10][10], C[10][10],m,n,p,q,k,I,j; cout<<\nEnter the rows and columns of Matrix A:; cin>>m>>n; cout<<\nEnter the rows and columns of Matrix B:; cin>>p>>q; 37
If(n==p) { cout<<\nEnter the elements of Matrix A:\n; for(i=0;i<m;++i) for(j=0<j<n;++j) cin>>A[i][j]; cout<<\nEnter the elements of Matrix B:\n; for(i=0;i<p;++i) for(j=0;j<q;++j) cin>>B[i][j]; cout<<\nMatrix A is:; for(i=0;i<m;++i) { cout<<\n; for(j=0<j<n;++j) cout<<A*i+*j+<<; } cout<<\nMatrix B is:; 38