Вы находитесь на странице: 1из 17

Click here for Short Answers

1 Explain tokens in C++. Also explain different types of literals in C++ by giving appropriate examples. Ans. Token: The smallest individual unit in a program is known as a Token. C++ has the following tokens: Keywords, Identifiers, Literals, Punctuators and Operators. 1. Keywords: The keywords are the words that convey a special meaning to the language compiler. Ex.- int,if,while, etc. 2. Identifier: An identifier is the name given by user for a unit of the program. 3. Literals: Literals are data items that never change their value during a program run. C++ allows several kinds of literals as following: i. Integer Constant: Integer constant are whole numbers without any fractional part. C++ allows three types of integer constant. For example 1234, +97. Decimal integer 8 will be written as 010 as octal integer constant. Decimal 12 will be written as 0XC as hexadecimal integer constant. ii. Character Constants: A character constant is single character enclosed in single quotes. For example, z. iii. Floating Constants: Floating constants are also called real constants. Real constants are numbers having fractional parts. Example of valid real constants in fractional form: 17.5, -13.0, -0.0625, 152E05, 0.1523E08, 152E+ 8, iv. String Literals: Multiple Character constants, if enclosed in double quotes; these are treated as string-literals. Each string literal is automatically added with a terminating character \0\. For example, abc. 2 Given three numbers A, B and C, write a program to write their values in an ascending order. For example, if A=12, B=10, and C=15, your program should print out: smallest number = 10 Can you take a little Next higher number = 12 Highest number = 15 Ans. #include<iostream.h> int main () { int a,b,c; cout<<"Enter three integers :"; cin>>a>>b>>c; cout<<endl; if (a>b && b>c) { cout<<"smallest number="<<c<<endl<<"higher number="<<b<<endl<<"highest number="<<a; } else if (a>c && c>b) cout<<"smallest number ="<<b<<endl<<" higher number= "<<c<<endl<<"highest number="<<a; else if (b>a && a>c) cout<<"smallest number ="<<c<<endl<<" higher number="<<a<<endl<<" highest number="<<b; else if (b>c && c>a) cout<<"smallest number ="<<a<<endl<<" higher number="<<c<<endl<<" highest number="<<b; else if (c>a && a>b) cout<<"smallest number="<<b<<endl<<"higher number="<<a<<endl<<"highest number"<<c; else cout<<"smallest number="<<a<<endl<<"higher number"<<b<<endl<<"highest number"<<c; cout<<endl; } 3 Write a program to accept three digits(i.e., 0-9) and print all possible combination s from these digits.(For example, if the three digits are 1, 2 and 3 then all possible combination are 123, 132, 231, 213, 312 and 321).
1

http://cbsecsnip.in

Ans. #include<iostream.h> #include<conio.h> void main() { clrscr(); const int s = 3; int a[s]; int x,y,z; for (int i=0; i<s; i++) cin >> a[i]; x = a[0]; y = a[1]; z = a[2]; i = 0; cout<<x<<y<<z; cout<<" "; while(1) { a[s] = a[i]; if (i != s - 1) { a[i] = a[i+1]; a[i+1] = a[s]; } else { a[i] = a[0]; a[0] = a[s]; i=-1; } i++; if (a[0] == x && a[1] == y && a[2] == z) break; for (int j = 0; j < s; j++) cout<<a[j]; cout<<" "; } getch(); } 4 Write a function that takes the time as three integer arguments (hours, minutes, seconds), and return the number of seconds since the clock last struct 112. Use this function to write a program to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock. Ans. #include<iostream.h> #include <stdio.h> #include <math.h> int getSeconds(int hours, int minutes, int seconds); int main(void) { int hour; int minute; int second; int secondsElapsed1; int secondsElapsed2; int secondsDifference;
2

http://cbsecsnip.in

cout<<"Enter first time: "; cin>>hour>>minute>>second; cout<<("%d seconds passed for 1st time you gave.\n"<<secondsElapsed1=getSeconds(hour,minute,second)); cout<<"Enter second time: "; cin>>hour>>minute>>second; cout<<"%d seconds passed for 2nd time you gave.\n"<<secondsElapsed2=getSeconds(hour,minute,second)); secondsDifference=abs(secondsElapsed1-secondsElapsed2); cout<<"Difference is %d seconds."<<secondsDifference; return 0; } int getSeconds(int hours, int minutes, int seconds) { return hours*3600+minutes*60+seconds; } 5 Computers are playing an increasing role in education. Write a program that will help elementary school students learn multiplication. Use rand to produce two positive one-digit integers. Your program should ask a question such as: how much is 6 time 7? The student then types the answer. Your program checks the students answer. Your program checks the students answer. If correct, print very Good! and then ask another question. If the answer is wrong, print No, Please Try Again. And then let the student try the same problem again until correct response is received. Ans. #include<iostream.h> #include<conio.h> #include<Time.h> #include<stdlib.h> const int Limit = 9; void main() { int n1, n2, pro = 1, ans = 0 ; char ch = 'y'; cout << "\n ************************ \n\n "; while(ch=='y' || ch == 'Y') { randomize(); n1 = random(Limit); randomize(); n2 = random(Limit); pro = n1 * n2; while(pro != ans ) { cout <<"\n How much is"<<n1<<"times"<<n2<< "?"; cout << "\n Enter your answer : "; cin >> ans; if(pro == ans ) cout << "\n Very Good!!!!"; else cout<< "No, Please Try again."; } pro = 1; ans = 0; cout << " Do you continue (Y/N)? "; cin >> ch; } getch();
3

http://cbsecsnip.in

} 6 Write a program that simulates the rolling of two dice. The program should use rand to roll the first die, and should read again to roll the second die. The sum of the two values should then be calculated. Note: Since each dice can show an integer from 1 to 6, then the sum of the two values will vary from 2 to 12 with 7 being the most frequent sums. Your program should roll the two dice100 times. Use a one-dimensional array to tally the number of times each possible sum appears. Print the results in tabular format. Ans. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<time.h> const int Limit = 6; void main() { int n1, n2, res; int arr[100]; cout <<"\n Roll 2 Dices 100 times Each & Check the sums\n"; cout << "\n ******* Check these out ********* \n\n "; for(int n=0; n< 100 ; n++) { cout << "\n YOUR TURN No. = " << n+1 << "\n"; cout << "\n Roll the first Dice "; randomize(); n1 = random(Limit); cout<< "\n Roll the sec dice :"; randomize(); n2 = random(Limit); res = n1 + n2; arr[n] = res; } cout<<"Now ,Guess the sum of the result of the rolling two dices~"; int g[100]; for(n=0;n<100;n++) { cout<< "\n Predict The Sum For Turn : " << n+1; cout << " Enter your number ( between 2 - 12) :"; cin >> g[n]; } cout << " \n If the guess number and actual number matches You WON "; cout<< "\n ***** TABLE *****\n"; cout << "\n TURN \t SUM \t GuessNo. \t RESULT? \n"; for( n=0 ; n< 100; n++) { if(g[n]==arr[n]) cout<<"\n "<< n+1<<"\t"<<arr[n]<<"\t"<<g[n]<<"\t" << "WON by guessing"; else cout<<"\n"<<n+1<<"\t"<<arr[n]<<g[n]<<"LOST by guessing"; if ( n == 15 || n == 35 || n == 55 || n == 75 ) { cout << "\n Press any key to continue :"; getch(); clrscr(); } } getch();
4

http://cbsecsnip.in

} 7 Write a program to find the LCM and GCD of two numbers. Ans. #include<iostream.h> #include<conio.h> void main() { int x,y,a,b,t,gcd,lcm; clrscr(); cout<<"Enter value of a and b:\n"; cin>>a>>b; x=a; y=b; while(b!=0) { t=b; b=a%b; a=t; gcd=a; lcm=(x*y)/gcd; } cout<<"\ngcd is:"<<gcd<<"\nlcm is:"<<lcm; getch(); } 8 Given a list of integers, Write a program to find those which are palindromes. For example, the number 4321234 is a palindrome as it reads the same from left to right and from right to left. Ans. #include<stdio.h> #include<iostream.h> void main() { long num,r,sum=0,temp; cout << "Enter a number: "; cin >> num; for(temp=num;num!=0;num=num/10){ r=num%10; sum=sum*10+r; } if(temp==sum) cout << temp << " is a palindrome"; else cout << temp << " is not a palindrome"; } 9 Write a C++ program to sum the sequence 1+1/1! + 1/2! + 1/3! + . Ans. #include<iostream.h> void main() { double n,sum=0,f=1,i; cout<<" Enter the value: "; cin>>n; for (i = 1; i <= n; i++) { f = f * i; sum = sum +(1 / f); } cout<<" Sum of the above series = %lf "<<sum+1; }
5

http://cbsecsnip.in

10

Write a C++ program to sum the sequence x-x2/2! + x4/4! x6/6! + x8/8! . Ans. #include<iostream.h> #include<stdio.h> #include<conio.h> void main() { float x,sum,term,denr; int i,n; clrscr(); cout<<"enter the Value of x and (n) Number of terms to be sum\t :"; cin>>x>>n; sum =x; term = 1; for (i=1;i<n;i++) { denr = (2*i)*(2*i-1); term = -term*x*x/denr; sum =sum+ term; } cout<<sum; getch(); } 11 Write a program to find the sum of the series x-x2/2! + x3/3! x4/4! + x5/5! x6/6! . Ans. #include<iostream.h> #include<conio.h> #include<math.h> int main() { clrscr(); int x,k; double sum=0.0; cout<<"Enter the value of x="; cin>>x; k=-1; for(int i=1;i<=6;++i) { k=k*-1; if(i==1) { sum=x; continue; } double fact=1.0; for(int j=1;j<=i;++j) { fact*=j; } sum+=((double)pow(x,i)/fact)*k; } cout<<"sum="<<sum; getch(); return 0; } 12 Write a function sum() in C++ with two arguments, double x and int n.
6

http://cbsecsnip.in

Ans. STUDENTS NOW TIME TO USE YOUR BRAIN...! 13 Write a function having two value parameters X and N with result type float to find the sum of series given below: 1+x1/2!+x2/3! +..+xN/(N+1)! Ans. STUDENTS NOW TIME TO USE YOUR BRAIN...! 14 Write a C++ function having two value parameters U and N with result type float to find sum of series given: 1-U+1/2!U2 1/3!U3+1/4!U4+..+ 1/N!UN Ans. #include<iostream.h>
#include<conio.h> #include<math.h> float Calculate(int,int); void main() { float X; int M; clrscr(); cout<<"Enter the limit of series: "; cin>>M; cout<<"Enter value for X: "; cin>>X; float Result = 1 - X; for(int i = 1; i <= M; i++) { if( (i%2) == 0) Result +=Calculate(i,X); else Result -=Calculate(i,X); } cout<<"Sum "<<Result; getch(); } float Calculate(int i,int X) { float s,power; double fact=1.0; for(int j=1;j<=i;++j) { fact*=j; power=pow(X,i); } s=(float)1/fact*power; return s; }

The function should return a value of type double and it should find the sum of the following series: 1 + x/1!+x3/2!+x5/3!+x7/4!+..+x2n-1/n!

15

Write a C++ function SUMFUN() having two parameters y (of type double) and m (of type integer) with a result type as double to find the sum of the series given below: y+y3/2!+y5/3!+y2m-1/m! Ans. #include<iostream.h> #include<math.h>
7

http://cbsecsnip.in

#include<conio.h> double SUMFUN(int y1,int m1); void main() { int y; int m; clrscr(); cout<<"Enter the vaue of Y and M"; cin>>y>>m; cout<<"\nThe sum of the series ="<<SUMFUN(y,m); getch(); } double SUMFUN(int y1,int m1) { double sum=0; double upper; for(int i=1;i<=m1;i++) { int f=1; for(int j=1;j<=i;j++) { f=f*j; } upper=pow(y1,(i*2-1)); sum=sum+upper/f; } return sum; } 16 Raising a number n to a power p is the same as multiplying n by itself p times . Write a function called power that takes two arguments, a double value takes two arguments, a double value for n and an int value for p, and returns the result as double value use default argument of 2 for p, so that if this argument is omitted that number will be squared. Write the main function that gets value from the user to test power function. Ans. #include<iostream.h> #include<conio.h> double power(double,int=2); int main() { int p; double n,r; cout<<"Enter number : "; cin>>n; cout<<"Enter exponent : "; cin>>p; r=power(n,p); cout<<"Result is "<<r; r=power(n); cout<<"\nResult without passing exponent is "<<r; getch(); return 0; } double power(double a, int b) { double x=1; for(int i=1;i<=b;i++)
8

http://cbsecsnip.in

x=x*a; return x; } Write a function called Zero_small() that has two integer arguments being passed by reference and sets the smaller of the two numbers too. Write the main program to access this function. Ans. #include<iostream.h> #include<conio.h> 17 void zero_small(int &,int &); int main() { int x,y; cout<<"Enter first number : "; cin>>x; cout<<"Enter second number : "; cin>>y; zero_small(x,y); cout<<"First number is : "<<x; cout<<"\nSecond number is : "<<y; getch(); return 0; } void zero_small(int &a, int &b) { if(a<b) a=0; else b=0; } 18 Write a program to determine all Pythagorean triplets in the range 100 to 1000. (A Pythagorean triplets is a set of three integers i, j, k such that i2+j2=k2) Ans. #include <iostream.h> #include <conio.h> void main(){ int side1, side2, hyp; clrscr(); cout<< " \n Pythagorean triples between 100 to 1000 :\n\n "; for( side1 = 100; side1<=1000 ; side1 ++) for( side2 = 100; side2<=1000 ; side2 ++) for( hyp = 100; hyp<=1000 ; hyp ++) if((side1*side1) + (side2*side2)==(hyp*hyp)) cout<< "\n"<<"("<<side1<<"\t"<< side2<<"\t"<<hyp<<")"; getch(); } 19 Write a C++ program to read a line of text from the keyboard and display the following information on the screen: (i) Number of words (ii) Number of characters #include <iostream.h> Ans. #include <conio.h> #include <stdio.h> #include <string.h> void main() { char sen[50];
9

http://cbsecsnip.in

20

int word_count = 0, chr = 0, space = 0; cout<< "\n Enter A String :"; gets(sen); for(int i = 0; sen[i] != '\0' ; i++) { if (sen[i] == ' ') space++; } chr = strlen(sen) - space; word_count = space + 1; cout<< "\n The Total no. of words = " << word_count; cout << "\n The total characters without spaces = " << chr; getch(); } From a two-dimensional array A[4][4], write a program to prepare a one-dimensional array B[16], that will have all the elements of A if they are stored in row-major form. For example, for the following array

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The resultant array should be [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] Ans. #include<iostream.h> #include<conio.h> void main( ) { int A[4][4], B[16]; for(int i = 0; i < 4 ; i++) for( int j = 0; j < 4 ; j++) { cout<<"\n Enter elements for "<< i+1 << "," << j+1 << "location :"; cin >> A[i][j]; } clrscr(); cout<<"\n The Original matrix : \n\n"; for( i = 0; i < 4 ; i++) { for( j = 0; j < 4 ; j++) cout<< A[i][j]<<"\t"; cout<< "\n"; } int k = 0; for( i = 0; i < 4 ; i++) for( j = 0; j < 4 ; j++) B[k] = A[i][j]; for( k=0; k<16; k++) cout<< B[k] << " "; getch( ); } 21 Write a C++ function that converts a 2-digit octal number into binary number and prints the binary equivalent. Ans. #include <iostream.h> #include <conio.h>
10

http://cbsecsnip.in

void octobin(int); void main() { clrscr(); int a; cout << "Enter a 2-digit octal number : "; cin>>a; octobin(a); getch(); } void octobin(int oct) { long bnum=0; int A[6]; int a1,a2,quo,rem; a2=oct/10; a1=oct-a2*10; for(int x=0;x<6;x++) { A[x]=0; } for (x=0;x<3;x++) { quo=a1/2; rem=a1%2; A[x]=rem; a1=quo; } for(x=3;x<6;x++) { quo=a2/2; rem=a2%2; A[x]=rem; a2=quo; } for(x=x-1;x>=0;x--) { bnum*=10; bnum+=A[x]; } cout <<"The binary number for the octal number " << oct << "is " << bnum << "." << endl; } 22 Write C++ program that uses various functions to sum following series: (i) (1) + (1+2) + (1+2+3) + (1+2+3+4) + up to N terms (ii) (22) + (22+42) +(22+42+62) +(22+42+62+82) up to N terms (iii) 1 + 1/3 + 1/5 + 1/7 + 1/9+.. Up to N terms. (iv) 1+1/x +1/x2 +1/x3+1/x4 +. Up to N terms. Ans. (i) #include<iostream.h> #include<conio.h> void main(){ int k=0; int m=0; clrscr(); cout<<"Enter the limit of the series: ";
11

http://cbsecsnip.in

cin>>m; for(int i=1;i<=m;i++) { for(int j=1;j<=i;j++) { k+=j; } } cout<<"Sum of the given series is: "<<k; getch(); } (ii) #include<iostream.h> #include<conio.h> void main() { int k=0; int m=0; int s=0; clrscr(); cout<<"Enter the limit of the series: "; cin>>m; for(int i=2;i<=m;i=i+2) { for(int j=2;j<=i;j=j+2) { s=j*j; k+=s; } cout<<endl; } cout<<"Sum of the given series is: "<<k; getch(); } (iii) #include<iostream.h> #include<conio.h> void main() { float k; int m=0; float s=1; clrscr(); cout<<"Enter the limit of the series: "; cin>>m; for(int j=3;j<=m;j=j+2) { k=(float)1/j; s+=k; } cout<<endl; cout<<"Sum of the given series is: "<<s; getch(); } 23 (iv) STUDENTS NOW TIME TO USE YOUR BRAIN...! Declare a structure to represent a complex no. ( a no. having a real and imaginary part). Write C++ function to
12

http://cbsecsnip.in

add, subtract, multiply and divide two complex numbers. Ans. #include<conio.h> #include<iostream.h> struct complexNo { float real; float img; }; typedef complexNo cm; void main() { cm n1, n2, res; cout<<"\nEnter 2 complex nos:"; cout<<"\n\n Enter 1st No.:"; cout<<"\n Real = ? "; cin>>n1.real; cout<<"\n Imaginary = ? "; cin>>n1.img; cout<<"\n Enter 2st No.:"; cout<<"\n Real = ? "; cin>>n2.real; cout<<"\n Imaginary = ? "; cin>>n2.img; res.real = n1.real +n2.real; res.img = n1.img + n2.img; cout<<"\n Sum of " << n1.real << " + i " << n1.img << " & " << n2.real << " +i " << n2.img << "is "<< res.real << " + i " + << res.img; res.real = n1.real -n2.real; res.img = n1.img - n2.img; cout<<"\n Diff. of " << n1.real << " + i " << n1.img << " & " << n2.real << " + res.img; res.real = n1.real *n2.real; res.img = n1.img *n2.img; cout<<"\n Product of " << n1.real << " + i " << n1.img << " & " << n2.real << " +i " << n2.img << "is "<< res.real << " + i " + << res.img; res.real = n1.real / n2.real; res.img = n1.img / n2.img; cout<<"\n Result od dividing of " << n1.real << " + i " << n1.img << " by " << n2.real << " +i " << n2.img << "is "<< res.real << " + i " + << res.img; getch(); } 24 Write a program to record score of a cricket match. One array stores information of batting team such as bat'sman name, runs scored, indication if out, mode by which out along with total runs, overs played, total overs and extras. The other array stores information about bowling team such as bowler's name, over's bowled, maiden overs, runs given, and wicked taken. The program reads in the above information and depending upon the user's choice, it displays either the batting team's information or the bowling team's information. Ans. #include<iostream.h> #include<conio.h> #include<stdio.h> struct batting
13

http://cbsecsnip.in

{ char batsman[20]; int run; int out; int tot_run; int overs; int total_over; int extra; }; struct bowling { char bowler[20]; int overs; int maiden_overs; int runs; int wicket; }; void main() { batting bat_team[12]; bowling bo_team[12]; cout<<"\n Enter records of batting team :\n\n"; for(int i = 0; i < 12 ; i++) { cout<<"\n Enter bat's man name :"; gets(bat_team[i].batsman); cout<<"\n Enter run scored :"; cin>>bat_team[i].run; cout<<"\n Type 0 NOT-OUT , Type 1 if OUT :"; cin>>bat_team[i].out; cout<<"\n Enter total run :"; cin>>bat_team[i].tot_run; cout<<"\n Enter no. of overs played :"; cin>>bat_team[i].overs; cout<<"\n Enter total over:"; cin>>bat_team[i].total_over; cout<<"\n Extra ?"; cin>>bat_team[i].extra; } cout<<"\n Enter records of bowling team :\n\n"; for( i = 0; i < 12 ; i++) { cout<<"\n Enter bowler's name :"; gets(bo_team[i].bowler); cout<<"\n Enter overs bowled :"; cin>>bo_team[i].overs; cout<<"\n Enter maiden overs :"; cin>>bo_team[i].maiden_overs; cout<<"\n Enter runs :"; cin>>bo_team[i].runs; cout<<"\n Enter wicked taken:"; cin>>bo_team[i].wicket; } char ch; int n; do
14

http://cbsecsnip.in

{ clrscr(); cout<<"\n Enter 1 to view batting team information:"; cout<<"\n Enter 2 to view bowling team information:"; cout<<"\n Enter your choice :"; cin>>n; switch(n) { case 1: cout<<"\n ************* BATTING TEAM *************\n"; cout<<"\n Name \t RUN-Scored Out Total-run Over's-played Total-Overs Extra "; for( i = 0; i < 12 ; i++) { cout<<"\n"<< bat_team[i].batsman <<"\t"<< bat_team[i].run<<" "; if(bat_team[i].out) cout<<"OUT"; else cout<<"NOT-OUT"; cout<< " " << bat_team[i].tot_run<< " " << bat_team[i].overs << " " << bat_team[i].total_over<< " "<< bat_team[i].extra; } break; case 2: cout<< "\n ************* BOWLING TEAM *************\n"; cout<< "\n Name \t Overs_bowled Maiden-Overs Runs-Given Wicket-Taken "; for( i = 0; i < 12 ; i++) { cout<< "\n"<< bo_team[i].bowler<< "\t"<< bo_team[i].overs<< " "; cout<< " "<< bo_team[i].maiden_overs<< " "<< bo_team[i].runs<< " "<< bo_team[i].wicket<<" "; } break; default: cout<< "\n Wrong choice."; } cout<<"\n Do you continue (y/n)"; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); } 25 An array stores details of 25 students (rollno, name, marks in 3 subjects). Write a program to create such an array and print out a list of students who have failed in more than one subject. Assume 40% as pass marks. Ans. #include<iostream.h> #include<conio.h> struct stud { int roll; char nm[50]; float m1, m2, m3; }; typedef stud S; void main()
15

http://cbsecsnip.in

{ S student[25]; for(int i =0 ; i < 25 ; i++) { cout << "\n Enter Roll no : "; cin >> student[i].roll; cout << "\n Enter Name : "; cin.getline(student[i].nm, 50); cout << "\n Enter marks of three subjects :"; cin >> student[i].m1 >>student[i].m2 >> student[i].m3 ; } cout<< "\n STUDENTS FAILED IN MORE THAN 1 SUBJECT \n "; for(i =0 ; i < 25 ; i++) { if(( student[i].m1< 40 && student[i].m2 < 40) || (student[i].m2 < 40 && student [i].m3 < 40) || ( student[i].m1 < 40 && student[i].m3 < 40)) cout << student[i].roll << "\t" << student[i].nm << "\n"; } getch(); } 26 A linear array if size 50 stores following information: name of the country, country's capital and per capita income of the country. Write a complete program in C++ to do the following : (a) To read a country's name and display capital and per-ca pita income. (b) To read name of the capital city and displays country's name and displays country's name and per capital income. Display an error message in case of an incorrect input. Ans. #include<iostream.h> #include<conio.h> struct country { char nm[30]; char capital[30]; float income; }; void main() { country c[50]; for( int i=0; i<50 ; i++) { cout << "\n Country's name : "; cin.getline(c[i].nm, 30); cout << "\n Country's capital :"; cin.getline(c[i].capital,30); cout << "\n Per capita income :"; cin >> c[i].income; } clrscr(); cout << "\n\n Sl No. \t Country \t Capital \t Per-Ca pita-Income \n :"; for( int i=0; i < 50 ; i++) { cout << i+1 << "\t" << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ; } cout << "\n *************************************************** \n ";
16

http://cbsecsnip.in

char ch = 'y'; char cap[30]; int flag = 0; while(ch == 'y' || ch == 'Y') { cout << "\n Enter Capital name : "; cin.getline(cap, 30); for(int k =0; k <50 ; k++) { flag = 0; if( strcmp( c[i].capital , cap ) == 0) { cout << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ; flag = 1; } if(flag == 0) cout << " Match not found !! "; cout<< "Do you want to continue ?(y/n)"; cin >> ch; } } }

Click here for Short Answers

We tried our best to give correct and accurate answers, if there is any suggestion or feedback please feel free to send us message from our contact us page.

17

http://cbsecsnip.in

Вам также может понравиться