Download presentation
Presentation is loading. Please wait.
Published byColeen Lamb Modified over 9 years ago
1
Lab Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased. Compute a sales tax of: 8 percent if the users purchase is less than $100 7.5 percent if the purchase is greater or equal to $100. Also if the purchase is over $500, give the customer an additional 10 percent after-tax discount. Print the purchase price, the amount of tax, the amount of the discount ($0.00 if no discount applies) and the total price. Output: Enter number of items purchased= 60 the purchase price= 60 $ the amount of tax= 4.8 $ the amount of the discount= 0.00$ the total price= 64.8 $ Enter number of items purchased= 510 the purchase price= 510$ the amount of tax= 38.25$ the amount of the discount= 54.82$ the total price= 493.42$
2
void main() { int i; float price,tax,d=0,TP; cout >i; price=i; if(price>0) { if(price 500) d=(price + tax)*10/100; TP=price+tax-d; cout<<“ the purchase price= "<<price<<'$'; cout<<"\n\n the amount of tax= "<<tax<<'$'; cout<<"\n\n the amount of the discount= "<<d<<'$'; cout<<"\n\n the total price= "<<TP<<'$'; } else { cout<<"wrong entry"; } getch(); }
3
Exercise : Write a program that request the user’s language and then print a greeting in that language. Output: Engl., Fren., Ger., Ital., or Rus. ? (e,f,g,i,r):e Welcome Where the greeting will be: English="Welcome" France="Bon jour" Germany=“Guten" Italian=“Bon giorno" Russian="Dobre utre"; Other language=“Sorry, we don't speak your language";
4
Void main() { char language; cout >language; if (language=='e') cout<<"Welcome"; else if (language=='f') cout<<"Bon jour"; else if (language=='g') cout<<"Guten"; else if (language=='i') cout<<"Bon giorno"; else if (language=='r') cout<<"Dobre utre"; else cout<<"Sorry, we don't speak your language"; getch(); }
5
Exercise : and write a c++ program that reads an integer number of two digits, then display each digit in a separate line after checking that the number consists of only two digits, otherwise display an appropriate message. Enter number of tow digits =13 3 1 output : Enter number of tow digits =684 Wrong Entry
6
void main() { int num; cout >num; if((num>=10) && (num<100)) { d1=num%10; d2=num/10; cout<<d1<<endl<<d2; } else cout<<“Wrong Entry"; getch(); }
7
Exercise: Write a program that reads a six-digits integer and prints the sum of its six digits. Use the quotient operator ( / ) and the reminder operator (%) to extract the digits from the integer. Output: Enter a six-digit integer: 342571 The sum of the digits of 34257 is 22
8
void main() { int n,sum ; cout >n; sum = n%10 + (n/10)%10 + (n/100)%10 + (n/1000)%10 + (n/10000)%10 + n/100000 ; cout<<“ The sum of the digits of “<< n <<” is: “<< sum; getch(); }
9
Exercise: Write a program that reads a character and determine if it is a vowel letter or not. vowel letters =(a, e, I, o, u) Output: ENTER any character: a a is a vowel letter. Output: ENTER any character: t t is not a vowel letter.
10
void main() { char le; cout >le; switch(le) { case 'a': case 'e': case 'i': case 'o': case 'u': cout<<le<<" is a vowel letter."; break; default : cout<<le<<" is not a vowel letter."; } getch(); }
11
Exercise: Output: - Square (sq) - Cube (c) -Squareroot (sr) - power (p) ENTER YOUR CHIOCE: sq enter your number: 2 4 - Square (sq) - Cube (c) - Squareroot (sr) - power (p) ENTER YOUR CHIOCE: p enter tow numbers: 2 3 8
12
#include #include #include #include void main() { char choice[3]; float x,y,z; cout >x; z=x*x; cout >x; z=sqrt(x); cout<<z; break; default : cout<<"error in index[1]"; } break; case 'c': case 'C': cout >x; z=x*x*x; cout >x>>y; z=pow(x,y); cout<<z; break; default : cout<<"error"; } getch(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.