c++ lab sheet kuppiya- 5

Lab sheet 5 තියෙන්නේ question 3යි.හැබයි ටිකක් විතර මොලෙන් ගේම ගහන්න වෙනවා.කර ගත්තොත් Exam ගොඩම තමයි.

21.You are to write a program that calculates the end-of-year bonus an employee receives. The bonus is based on the employee’s annual salary and their performance rating according to the following scale

  • Prompt the user to enter the annual total of sales made by a salesperson.
  • Use a nested if else statement to determine the bonus according to the table below
    • If sales < 50000 no bonus
    • If sales are greater than or equal 50000 but less then 100000 bonus = 10% of sales
    • If sales are greater than or equal to 100000 then bonus = 20% of sales.
  • Display sales and bonus.

#include <iostream.h>

int main()
{
float sale;
cout<<“Please enter total of anual sales:”;
cin>>sale;
if(sale<50000)
{
cout<<“sale =”<<sale<<endl;
cout<<“You have not bonus\n”;
}
else if(sale<100000)
{
cout<<“sale =”<<sale<<endl;
cout<<“bonus=”<<sale*10/100<<endl;
}
else
{
cout<<“sale =”<<sale<<endl;
cout<<“bonus=”<<sale*20/100<<endl;
}

return 0;
}

22. Write program given a 5 digit amount in rupees prints the number of 1000/=,500/=,200/=,100/=,50/=,20/=,10/=,5/=,2/=,1/= notes and coins needed

Eg:- Amount=2754.00

Your program should print as follows

 

1000-Notes-2

500 Notes-1

200 Notes-2

100 Notes-0

50 Notes-1

20Notes-0

10 Notes-0

5Notes-0

2Notes-2

1Notes-0

 

Hint:-

1000 Rupee notes=2754/1000=2

Remaining Amount =2754%1000=754

You need to use suitable variables.

#include <iostream.h>

int main()
{
int a,b,c,d,e,f,g,h,i,j;
int amo,rem1,rem2,rem3,rem4,rem5,rem6,rem7,rem8,rem9;
cout<<“Enter amount:”;
cin>>amo;
cout<<“”<<endl;
a=amo/1000;
rem1=amo%1000;
b=rem1/500;
rem2=rem1%500;
c=rem2/200;
rem3=rem2%200;
d=rem3/100;
rem4=rem3%100;
e=rem4/50;
rem5=rem4%50;
f=rem5/20;
rem6=rem5%206;
g=rem6/10;
rem7=rem6%10;
h=rem7/5;
rem8=rem7%5;
i=rem8/2;
rem9=rem8%2;
j=rem9/1;
cout<<“1000-Notes-“<<a<<“\n”
” 500-Notes-“<<b<<“\n”
” 200-Notes-“<<c<<“\n”
” 100-Notes-“<<d<<“\n”
” 50-Notes-“<<e<<“\n”
” 20-Notes-“<<f<<“\n”
” 10-Notes-“<<g<<“\n”
” 5-Notes-“<<h<<“\n”
” 2-Notes-“<<i<<“\n”
” 1-Notes-“<<j<<“\n”;

return 0;
}

23.Write a program that takes an integer keyed in from the terminal and extracts and

displays each digit of the integer in English. So, if the user types in 932, the program

should display :

nine three two

Remember to display “zero” if the user types in just a 0.

#include <iostream.h>

int main()
{
int val,val1,val2,val3,val4,val5,val6,val7,val8,val9;
int a,b,c,d,e,f,g,h,i,j,x;
cout<<“please enter valuve:”;
cin>>val;
cout<<“”<<endl;
a=val/1000000000;
val1=val%1000000000;
b=val1/100000000;
val2=val1%100000000;
c=val2/10000000;
val3=val2%10000000;
d=val3/1000000;
val4=val3%1000000;
e=val4/100000;
val5=val4%100000;
f=val5/10000;
val6=val5%10000;
g=val6/1000;
val7=val6%1000;
h=val7/100;
val8=val7%100;
i=val8/10;
val9=val8%10;
j=val9/1;
x=a;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=b;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=c;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=d;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=e;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=f;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=g;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=h;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=i;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
x=j;
if(x==1)cout<<“one “;
else if(x==2)cout<<“two “;
else if(x==3)cout<<“three “;
else if(x==4)cout<<“four “;
else if(x==5)cout<<“five “;
else if(x==6)cout<<“six “;
else if(x==7)cout<<“seven “;
else if(x==8)cout<<“eight “;
else if(x==9)cout<<“nine “;
else cout<<“zero “;
cout<<“”<<endl;

return 0;
}

කුප්පිය ගැන ඔයාලගේ අදහස් යෝජනා පහලින් comment කරගෙනම යන්න..ස්තුතියි

252 thoughts on “c++ lab sheet kuppiya- 5

Leave a Reply

Your email address will not be published. Required fields are marked *