A program uses a char variables named department and two double variables names
ID: 3632978 • Letter: A
Question
A program uses a char variables named department and two double variables names salary and raise. Te department variables contains one of the following letters( entered in either uppercase or lowercase): A, B, or C. Employees in department A and B are receiving a 2% raise. Employees in department C are receiving a 1.5% raise. Write the c++ code to calculate and display the appropriate raise amount. Display the raise amount in fixed-point notation with two decimal places.
This is what I have but I cant run it . Confused on what to save it as, in Microsoft Visual C++ 2010. How do I run it? Does It need it to be empty project, win 32 console, class libray. I just came out of java and net beans was so simple. I think i am just missing a step or two.
But here is my code for the question above. Please help, I have 6 more homework questions to do.
<code>
#include <iostream>
#include <iomanip>
using namespace std:
int main()
{
//declare named constants and variables
const double RATE1 = .02;
const double RATE2 = .015;
char code = ' ';
double currentPay = 0.0;
double raise =0.0;
double newPay =0.0;
//enter input items
cout << "Pay code: ";
cin >> code;
cout << "CurrentPay: ";
cin >> quantity;
//calcualte raise and new pay
if (code == 'A' || code == 'B')
raise = currentPay * RATE2;
else
raise = currentPay * RATE1;
//end if
newPay = currentPay + raise;
//display new pay
cout << fixed << setprecision(2);
cout << "New pay: $" << newPay << endl;
system("pause");
return 0;
}
<code>
Explanation / Answer
char department;double salary;
double raise;
printf("Enter department (A, B or C): ");
scanf_s("%c", &department);
printf("Enter employee salary: $");
scanf_s("%lf", &salary);
if (toupper(department) == 'A' || toupper(department) == 'B')
raise = salary * 0.02;
else if (toupper(department) == 'C')
raise = salary * 0.015;
else
raise = 0;
printf("The calculated raise is $%.2lf ", raise);
OR #include <iostream>
#include <iomanip>
using namespace std;
class Raise
{
public:
char department;
double salary;
double raise;
double new_salary;
void setNewSalary() {new_salary = salary + salary * raise;}
void show();
};
void Raise::show()
{
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
cout << "new salary for department " << department << " is: " << setprecision(2) << new_salary << "." << endl;
}
int main()
{
Raise A = {'A', 1500.588, 0.02};
Raise B = {'B', 1200.789, 0.02};
Raise C = {'C', 2000.956, 0.015};
A.setNewSalary();
A.show();
B.setNewSalary();
B.show();
C.setNewSalary();
C.show();
cin.get();
return 0;
} OR #include <iostream>
using namespace std;
int main()
{
char department;
double salary;
double raise;
cout << "Enter department (A, B or C): ";
cin >> department;
cout << "Enter employee salary: ";
cin >> salary;
if ( (department== 'A') || (department== 'B') ) {
raise = salary * 0.02;
}
else if (department=='C') {
raise = salary * 0.015;
}
else
raise = 0;
cout << "The calculated raise is $" << raise << endl;
system("pause");
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.