In: Computer Science
A construction company has 3 categories of casual
workers. Category A,B and C. Workers in categories A are paid 1000
per day for first 25 days, you are paid 800 per day for less than
25 days, any extra day after 25th you are paid 1200 per day. In
categorie B you are paid 800 per day if you work for 25 days
otherwise you are paid 600 per day if you work for less than 25
days . 1000 per day for any day after 25th.
Category C 600 per day for 25 days , 400 per day for days before 25
days and 800 per day for days after 25th day
Question
1.write an algorithm
2. Translate to flowchart
3. Translate into actual program using C++
Here is the solution to above program PLEASE GIVE A THUMBS UP IF YOU LIKE THE SOLUTION
1) Write an Algorithm
calculateMoney(category,days)
{
money=0;
if(category=='A')
{
if(days>=25)
{
money+=25*1000 + (days-25)*1200;
}
else
{
money=days*800;
}
}
else if(category=='B')
{
if(days>=25)
{
money+=25*800 + (days-25)*1000;
}
else
{
money=days*600;
}
}
else if(category=='C')
{
if(days>=25)
{
money+=25*600 + (days-25)*800;
}
else
{
money=days*400;
}
}
return money;
}
2) Translate to flowchart
C) C++ PROGRAM . please refer to code screenshot for indentation and help via comments
C++ CODE
#include <iostream> using namespace std; int main() { char ch; int days; int money=0; //taking user input for the customer cout<<"Enter the category of a worker (A|B|C): "; cin>>ch; cout<<"Enter the number of days he/she worked: "; cin>>days; //checking is worker from category A if(ch=='A') { if(days>=25) { money+=25*1000 + (days-25)*1200; } else { money=days*800; } } //checking if worker is from category B else if(ch=='B') { if(days>=25) { money+=25*800 + (days-25)*1000; } else { money=days*600; } } //checking if worker is from category C else if(ch=='C') { if(days>=25) { money+=25*600 + (days-25)*800; } else { money=days*400; } } //printing the money made by the worker cout<<"Money Paid to Worker is "<<money<<endl; return 0; }
OUTPUT OF CODE
SCREENSHOT OF CODE