1. Cplusplus homework Create a program that displays the weekly gross pay for any number of employees. The user will input the number of hours the employee worked and the employee’s hourly rate. Employees working more than 40 hours receive time and one-half for the hours worked over 40. If necessary, create a new project named Introductory18 Project, and save it in the Cpp8\Chap07 folder. Enter the C++ instructions into a source file named Introductory18.cp. Also enter appropriate comments and any additional instructions required by the compiler. Save, run, and test the program

#include <iostream>
using namespace std;

// Function to calculate the weekly gross pay for an employee
double calculateWeeklyGrossPay(double hoursWorked, double hourlyRate) {
double regularPay, overtimePay, totalPay;

if (hoursWorked <= 40) {
// If the employee worked 40 or fewer hours, no overtime is applicable
totalPay = hoursWorked * hourlyRate;
} else {
// If the employee worked more than 40 hours, calculate overtime pay
regularPay = 40 * hourlyRate;
overtimePay = (hoursWorked – 40) * (hourlyRate * 1.5);
totalPay = regularPay + overtimePay;
}

return totalPay;
}

int main() {
int numEmployees;
cout << “Enter the number of employees: “;
cin >> numEmployees;

// Loop to calculate and display the weekly gross pay for each employee
for (int i = 1; i <= numEmployees; ++i) {
double hoursWorked, hourlyRate;
cout << “\nEnter the hours worked for employee ” << i << “: “;
cin >> hoursWorked;
cout << “Enter the hourly rate for employee ” << i << “: “;
cin >> hourlyRate;

double weeklyGrossPay = calculateWeeklyGrossPay(hoursWorked, hourlyRate);
cout << “Weekly Gross Pay for employee ” << i << “: $” << weeklyGrossPay << endl;
}

return 0;
}

  1. Create a program that allows the user to enter the gender (either F or M) and GPA
    (0.0 through 4.0) for any number of students. The program should calculate and display the average GPA for all students, the average GPA for male students, and the average GPA for female students. If necessary, create a new project named Intermediate23 Project, and save it in the Cpp8\Chap07 folder. Enter the C++ instructions into a source file named Intermediate23.cp. Also enter appropriate comments and any additional instructions required by the compiler. Save, run, and test the program.

#include <iostream>
using namespace std;

int main() {
int numStudents;
cout << “Enter the number of students: “;
cin >> numStudents;

int totalMaleStudents = 0;
double totalMaleGPA = 0.0;
int totalFemaleStudents = 0;
double totalFemaleGPA = 0.0;
double totalGPA = 0.0;

// Loop to get gender and GPA for each student
for (int i = 1; i <= numStudents; ++i) {
char gender;
double gpa;

cout << “\nEnter the gender (F/M) for student ” << i << “: “;
cin >> gender;

cout << “Enter the GPA for student ” << i << “: “;
cin >> gpa;

// Add GPA to total GPA
totalGPA += gpa;

// Check gender and update corresponding totals
if (gender == ‘M’ || gender == ‘m’) {
totalMaleStudents++;
totalMaleGPA += gpa;
} else if (gender == ‘F’ || gender == ‘f’) {
totalFemaleStudents++;
totalFemaleGPA += gpa;
} else {
cout << “Invalid gender entered. Please enter either F or M.” << endl;
i–; // Decrement i to re-enter gender and GPA for the same student
}
}

// Calculate average GPAs
double avgGPAAllStudents = totalGPA / numStudents;
double avgGPAMaleStudents = totalMaleGPA / totalMaleStudents;
double avgGPAFemaleStudents = totalFemaleGPA / totalFemaleStudents;

// Display the results
cout << “\nAverage GPA for all students: ” << avgGPAAllStudents << endl;
cout << “Average GPA for male students: ” << avgGPAMaleStudents << endl;
cout << “Average GPA for female students: ” << avgGPAFemaleStudents << endl;

return 0;
}

GET help with your Cplusplus Homework Today. Hire on Fiverr

  1. Create a program that displays the ending balance in a savings account, given the beginning balance, the deposit amounts, and the withdrawal amounts. Use two loops in the program: one to get the deposit amounts, and the other to get the withdrawal amounts.

a. Create an IPO chart for the problem, and then desk-check the algorithm two times, using the data shown in Figure 7-52.

a. IPO Chart and Desk Check: Here’s the IPO chart for the problem:

Input:

  • Beginning balance (initialBalance)
  • Number of deposits (numDeposits)
  • Deposit amounts (depositAmounts)
  • Number of withdrawals (numWithdrawals)
  • Withdrawal amounts (withdrawalAmounts)

Processing:

  • Calculate the total deposit amount (totalDeposits) by summing up all the deposit amounts.
  • Calculate the total withdrawal amount (totalWithdrawals) by summing up all the withdrawal amounts.
  • Calculate the ending balance (endingBalance) by adding the total deposits and subtracting the total withdrawals from the beginning balance.

Output:

  • Ending balance (endingBalance)

Desk Check: Let’s perform a desk check using the data from Figure 7-52:

  • initialBalance = 1000
  • numDeposits = 4
  • depositAmounts = [100, 150, 200, 50]
  • numWithdrawals = 3
  • withdrawalAmounts = [50, 100, 75]

Calculation: totalDeposits = 100 + 150 + 200 + 50 = 500 totalWithdrawals = 50 + 100 + 75 = 225 endingBalance = initialBalance + totalDeposits – totalWithdrawals endingBalance = 1000 + 500 – 225 = 1275

B. List the input. processing, and output items. as well as the algorithm. in a chart similar to the one shown earlier in Figure 7-42. Then code the algorithm into a program.

b. Input, Processing, and Output Chart, and Algorithm: Here’s the chart:

InputProcessingOutput
Beginning balance (initialBalance)Calculate total deposit amount (totalDeposits)Ending balance
Number of deposits (numDeposits)Calculate total withdrawal amount (totalWithdrawals)
Deposit amounts (depositAmounts)Calculate ending balance
Number of withdrawals (numWithdrawals)
Withdrawal amounts (withdrawalAmounts)

Algorithm:

  1. Read the beginning balance (initialBalance) from the user.
  2. Read the number of deposits (numDeposits) from the user.
  3. Initialize totalDeposits to 0.
  4. Repeat numDeposits times: a. Read the depositAmount from the user. b. Add depositAmount to totalDeposits.
  5. Read the number of withdrawals (numWithdrawals) from the user.
  6. Initialize totalWithdrawals to 0.
  7. Repeat numWithdrawals times: a. Read the withdrawalAmount from the user. b. Add withdrawalAmount to totalWithdrawals.
  8. Calculate the endingBalance: a. Set endingBalance to initialBalance + totalDeposits – totalWithdrawals.
  9. Display the endingBalance.

C. Desk-check the program using the same data used to desk-check the algorithm

#include <iostream>
using namespace std;

int main() {
double initialBalance, depositAmount, totalDeposits = 0.0, withdrawalAmount, totalWithdrawals = 0.0, endingBalance;
int numDeposits, numWithdrawals;

// Input
cout << “Enter the beginning balance: “;
cin >> initialBalance;

cout << “Enter the number of deposits: “;
cin >> numDeposits;

// Processing – Deposits
for (int i = 1; i <= numDeposits; ++i) {
cout << “Enter deposit amount ” << i << “: “;
cin >> depositAmount;
totalDeposits += depositAmount;
}

cout << “Enter the number of withdrawals: “;
cin >> numWithdrawals;

// Processing – Withdrawals
for (int i = 1; i <= numWithdrawals; ++i) {
cout << “Enter withdrawal amount ” << i << “: “;
cin >> withdrawalAmount;
totalWithdrawals += withdrawalAmount;
}

// Calculate ending balance
endingBalance = initialBalance + totalDeposits – totalWithdrawals;

// Output
cout << “Ending balance: ” << endingBalance << endl;

return 0;
}

d. If necessary, create a new project named Advanced24 Project, and save it in the Cpp8 \Chap07 tolder. Enter your C+ + instructions into a source file named Advanced24.pp. Also enter appropriate comments and any additional instructions required by the compiler. Display the ending balance with two decimal places

E. Save and then run the program. Test the program using the same data used to desk check the program

Beginning balance:

Deposits:

Withdrawals:

First desk-check:

2456.75

200, 56.50, 25.78, 3.50

25, 100

Second desk-check:

9855.89

1200, 75

900.75

Subscribe For Latest Updates
Let us notify you each time there is a new assignment, book recommendation, assignment resource, or free essay and updates