Upcoming SlideShare
×

# C++ programming

862 views

Published on

CBSE Class XI Programs in C++

• Full Name
Comment goes here.

Are you sure you want to Yes No
• thnks !!!!!

Are you sure you want to  Yes  No

### C++ programming

1. 1. The Programs
2. 2. S. No. To Find Given 1. nth term When first term, common difference,value of n Is Given 2. Sum of n terms 3. Arithematic Mean enter first term, common difference,value of n 4. n if nth term is given enter first term, common difference, Enter nth term 5. n if sum of n term is given enter first term, common difference, sum of n terms
3. 3.  Code#include<iostream.h> #include<conio.h> #include<math.h> int main() { clrscr(); int ch; float a,nth,n,d,s,AM,i,j; cout<<"n"; cout <<"Choice Menu"<<"n"; cout<<"n"; cout<<"1. nth term"<<"n"; cout<<"2. Sum of n terms"<<"n"; cout<<"3. Arithematic Mean"<<"n"; cout<<"4. n if nth term is given"<<"n"; cout<<"5. n if sum of n term is given"<<"n"; cin>>ch; switch(ch) { case 1 : cout<<"enter first term, common difference,value of n"; cin>>a>>d>>n; nth = a + (n-1)*d; cout<<"the nth term is"<<nth<<"n"; break; case 2 : cout<<"enter first term, common difference,value of n"; cin>>a>>d>>n; s = n/2*((a+a) +(n -1))*d; cout<<"the sum is "<<s; break; case 3 : cout<<"enter first term, common diff.,value of n"; cin>>a>>d>>n; nth = a + (n-1)*d; AM = (a + nth)/2; cout<<"the AM is"<<nth<<"n"; break; case 4 : cout<<"enter first term, common difference, Enter nth term"; cin>>a>>d>>nth; n = (nth - a + d)/d; cout<<"the value of n is " <<n; break; case 5 : float b,c,e,f,g,h,i,m; cout<<"enter first term, common difference, Enter sum of n term"; cin>>a>>d>>s; h= (d -(2*a)); b =(-((2*a)- d)); c = pow(h,2.0); e = (8*d*s); g =(c+e); f =sqrt(g); n =(b + f)/2*d ; i =(b - f)/2*d ; if (i < 0) cout<<"the value of n is " <<n; else cout<<"the value of n is " <<n<<"or"<<m; break; } getch (); return 0;
4. 4. The resultant value when a number is given with the power to which it has to be raised for any given number For Eg :- 5 raise to 3 is 125
5. 5. Code #include<iostream.h> #include<conio.h> #include<math.h> int main() { clrscr(); float number, power, answer; cout<<"enter the number :- "; cin>>number; cout<<"enter the power of the number :- "; cin>>power; answer = pow (number,power); cout<< number<<" raised to "<< power<<" is "<< answer; getch(); return 0; }
6. 6. A quiz in C++
7. 7. € Code #include<iostream.h> #include<conio.h> int main() { clrscr(); int IQ, ch1,ch2, ch3, ch4; int pnt = 0; cout<<"Qs.1)In how many ways cane we rename a file "<<"n"; cout<<"1.1 way "<<"n"; cout<<"2.3 ways "<<"n"; cout<<"3.5 ways "<<"n"; cout<<"4.Can't say "; cin>>ch1; if (ch1==2) { pnt =(pnt + 3); cout<<"correct Answer............."; } else cout<<"wrong Answer..............."; cout<<"n"; cout<<"Qs. 2) fullstop is a valid character for filename in Win Xp. What about its validity in Win 7 "<<"n"; cout<<"1.Valid "<<"n"; cout<<"2.Unvalid "<<"n"; cin>>ch2; if (ch2==2) { pnt =(pnt + 3); cout<<"correct Answer.............."; } else cout<<"wrong Answer................"; cout <<pnt; cout<<"n"; cout<<"Qs.3)The inventing country of supercomputer PACE is "<<"n"; cout<<"1.India "<<"n"; cout<<"2.China "<<"n"; cout<<"3.Japan "<<"n"; cin>>ch3; if (ch3==1) { pnt =(pnt + 3); cout<<"correct Answer............."; } else cout<<"wrong Answer..............."; cout<<"n";
8. 8. cout<<"Qs.4)Uninitialized variable will give as outputcout<<"Qs.4)Uninitialized variable will give as output "<<"n";"<<"n"; cout<<"1.Garbage Value "<<"n";cout<<"1.Garbage Value "<<"n"; cout<<"2.zero "<<"n";cout<<"2.zero "<<"n"; cout<<"3.No output "<<"n";cout<<"3.No output "<<"n"; cin>>ch4;cin>>ch4; if (ch4==1)if (ch4==1) {{ pnt =(pnt + 3);pnt =(pnt + 3); cout<<"correct Answer.............";cout<<"correct Answer............."; }} elseelse cout<<"wrong Answer...............";cout<<"wrong Answer..............."; cout<<"n";cout<<"n"; IQ = pnt/3;IQ = pnt/3; cout<<"please Wait"<<"n";cout<<"please Wait"<<"n"; cout<<"Generating Result"<<"n";cout<<"Generating Result"<<"n"; cout<< "you Answered "<<IQ<<" question correctly";cout<< "you Answered "<<IQ<<" question correctly"; cout<<" your score is:- "<< pnt;cout<<" your score is:- "<< pnt; getch();getch(); return 0;return 0; }} € Code continued
9. 9. To determine whether the area of the given rectangle is greater then it’s perimeter or not
10. 10.  Code #include<iostream.h>#include<iostream.h> #include<conio.h>#include<conio.h> int main ()int main () {{ clrscr();clrscr(); float l,b, p, a;float l,b, p, a; cout<<"enter length, bredth of the rectangle";cout<<"enter length, bredth of the rectangle"; cin>>l>>b;cin>>l>>b; p = 2* (l +b);p = 2* (l +b); a = l*b;a = l*b; if (a >p)if (a >p) cout <<"the area is greater then the permeter"<<"n";cout <<"the area is greater then the permeter"<<"n"; elseelse cout<<"the area is smaller then the perimeter"<<"n";cout<<"the area is smaller then the perimeter"<<"n"; cout<<"perimeter :-"<<p<<"n";cout<<"perimeter :-"<<p<<"n"; cout<<"area :-"<<a;cout<<"area :-"<<a; getch();getch(); return 0;return 0; }}
11. 11. To determine the compound interest on given amount for a given period and rate
12. 12. Code #include <iostream.h>#include <iostream.h> #include<conio.h>#include<conio.h> #include<math.h>#include<math.h> int main()int main() {{ clrscr();clrscr(); float P,R,N,A,H,B;float P,R,N,A,H,B; cout<<"Enter Principle Amount: ";cout<<"Enter Principle Amount: "; cin>> P;cin>> P; cout<<"Enter Rate of Interest: ";cout<<"Enter Rate of Interest: "; cin>> R;cin>> R; cout<<"Enter Time Period (in years): ";cout<<"Enter Time Period (in years): "; cin>>N;cin>>N; H = (1 + R/100);H = (1 + R/100); B = pow (H,N);B = pow (H,N); A = (P*B);A = (P*B); cout<<"Principle Amout Rs."<<P<<"n";cout<<"Principle Amout Rs."<<P<<"n"; cout<<"Rate of Interest "<<R<<" %"<<"n";cout<<"Rate of Interest "<<R<<" %"<<"n"; cout<<"Time Period "<<N<<" years"<<"n";cout<<"Time Period "<<N<<" years"<<"n"; cout<<"the compoud interest for the given amount is Rs."<<A;cout<<"the compoud interest for the given amount is Rs."<<A; getch();getch(); return 0;return 0; }}
13. 13. To determine the Quotient and RemainderTo determine the Quotient and Remainder when a given number is divided by anotherwhen a given number is divided by another given numbergiven number
14. 14. σ CodeCode #include <iostream.h>#include <iostream.h> #include<conio.h>#include<conio.h> int main ()int main () {{ clrscr();clrscr(); int a,div,b,num;int a,div,b,num; cout<<"enter the number to be divided";cout<<"enter the number to be divided"; cin>>num;cin>>num; cout<<"enter the number by which "<<num<<" has to be divided";cout<<"enter the number by which "<<num<<" has to be divided"; cin>>div;cin>>div; a = num/div;a = num/div; b = num%div;b = num%div; cout<<num<<" divided by "<<div<<" gives "<<"n";cout<<num<<" divided by "<<div<<" gives "<<"n"; cout <<"quotient as "<<a<<"n";cout <<"quotient as "<<a<<"n"; cout <<"remainder as "<<b;cout <<"remainder as "<<b; getch();getch(); return 0;return 0; }}
15. 15. To determine the result when a givenTo determine the result when a given number is raised to all numbers from 1 tonumber is raised to all numbers from 1 to the given valuethe given value
16. 16. ∏ Code #include<iostream.h>#include<iostream.h> #include<conio.h>#include<conio.h> #include<math.h>#include<math.h> #include<process.h>#include<process.h> int main ()int main () {{ clrscr();clrscr(); int num, por;int num, por; cout<<"Enter the number whose powers are to be listed";cout<<"Enter the number whose powers are to be listed"; cin>>num;cin>>num; cout<<"enter the power till you want the powers to be listed";cout<<"enter the power till you want the powers to be listed"; cin>>por;cin>>por; for ( int i = 1;i <= por; i++)for ( int i = 1;i <= por; i++) cout << pow(num,i)<<"n";cout << pow(num,i)<<"n"; getch ();getch (); return 0;return 0; }}
17. 17. To Know the money present in a customer’s account at the end of specific time. Given amount deposited and time period
18. 18.  Code #include<iostream.h> #include<conio.h> #include<math.h> #include<process.h> int main () { clrscr(); float amt, rt, A, H, B; int yrs,ch; cout<<"enter amount deposited"; cin>>amt; cout<<"number of years"; cin>>yrs; cout<<"n"; cout<<"choose most appropriate option about your amonut and time period"<<"n"; cout<<"1. amout less than 2000, yrs more than 1"<<"n"; cout<<"2. amout between 2000 and 6000,yrs more than or equal to 1 "<<"n"; cout<<"3. amout more than 6000, yrs more than or equal to 1"<<"n"; cout<<"4. yrs more than or equal to 5"<<"n"; cout<<"5. none of the above "; cin>>ch; switch(ch) { case 1:rt =5; break; case 2:rt =7; break; case 3:rt =8; break; case 4:rt =10; break; case 5:rt = 3; break; } H = (1 + rt/100); B = pow( H, yrs); A = (amt * B); cout <<" the C. I for the "<<A; getch(); return 0; }
19. 19. To find the entered amount’s value in another country’s currency Serial no.Serial no. Amount entered inAmount entered in Resulting amount inResulting amount in 11 INRINR US \$US \$ 22 US \$US \$ INRINR 33 INRINR EuroEuro 44 EuroEuro INRINR 55 INRINR YenYen 66 YenYen INRINR
20. 20. δ Code #include<iostream.h> #include<conio.h> #include<process.h> int main() { clrscr(); int ch; float inri, inra, usdi, usda,inrie, inrae,euri, eura,inriy,inray,yeni,yena; cout<<"Choose from and to (currency)"<<"n"; cout<<"1.INR to US \$"<<"n"; cout<<"2.US \$ to INR"<<"n"; cout<<"3.INR to Euro"<<"n"; cout<<"4.Euro to INR"<<"n"; cout<<"5.INR to Yen "<<"n"; cout<<"6.Yen to INR "<<"n"; cin>>ch; switch(ch) { case 1:cout<<"Enter amount in INR(Indian National Rupee) :-"; cin>>inri; inra = (inri/53); cout<<inri<<" rupees are equal to "<<inra<<" US \$"<<"n"; break; case 2:cout<<"Enter amount in US \$ (US dollars) :-"; cin>>usdi; usda = (usdi * 53); cout<<usdi<<" US \$ are equal to "<<usda<<"Indian rupees "<<"n"; break; case 3:cout<<"Enter amount in INR(Indian National Rupee) :-"; cin>>inrie; inrae = (inrie/70); cout<<inrie<<" rupees are equal to "<<inra<<" Euro's"<<"n"; break; case 4:cout<<"Enter amount in Euro's :-"; cin>>euri; eura = (euri * 70); cout<<euri<<" Euor's are equal to "<<eura<<"Indian rupees "<<"n"; break; case 5:cout<<"Enter amount in INR(Indian National Rupee) :-"; cin>>inriy; inray = (inriy*1.4); cout<<inriy<<" rupees are equal to "<<inra<<" Yen"<<"n"; break; case 6:cout<<"Enter amount in Yen's :-"; cin>>yeni; yena = (yeni/1.4); cout<<inri<<" Yen are equal to "<<inra<<" Indian rupees"<<"n"; break; } getch(); return 0; }
21. 21. To know the amount of solar energy received in the given area over a given period of time
22. 22. Code #include<iostream.h> #include<conio.h> int main () { clrscr(); int t; float ar,s; float S = 1.4; cout<<"enter area(mt. sq.), time (sec)"; cin>>ar>>t; s = ar*t*60*1.4; cout<<"solar energy recieved ="<<s<<"kJ"; getch(); return 0; }
23. 23. THANKTHANK YOUYOU