Question

In: Computer Science

You have been approached by the Statistics Canada to create a C# program to calculate the...

You have been approached by the Statistics Canada to create a C# program to calculate the average salary of people with university degrees, college diplomas, and high school diplomas. Using a while loop, you are to process salary data until the user indicates that you should stop (there could be 0 or more data values). For each person processed, the program must first input an education type (char edType) (‘U’ or ‘u’ for university degrees, ‘C’ or ‘c’ for college diplomas, and ‘H’ or ‘h’ for high school) and then a salary (double salaryData). The program stops accepting input when the user enters a ‘Q’ or ‘q’ for quit (use a sentinel value while loop). Your main data processing loop should be conditioned on the fact that the user has not signalled quit. It might look something like:

while(char.ToUpper(edType) != ‘Q’)

This implies that like any sentinel value loop, you must seed the loop (input a value) PRIOR to entering the loop. Inside the loop the salary data is entered and processed. Once the main loop terminates, the average salary for each of the three education types should be printed out. Be sure to print an error message if the user enters an invalid education type or a negative salary.

Solutions

Expert Solution

//C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace salaryCalculator
{
class Program
{
static void Main(string[] args)
{
char edType;
double salary;
double sumUniversity = 0, sumCollege = 0, highSchool = 0;
int uniCounter = 0, collegeCounter = 0, highSchoolCounter = 0;
do
{
Console.Write("Enter education Type ((U)niversity,(C)ollege,(H)ighSchool, (Q)uit): ");
edType = Console.ReadKey().KeyChar;
switch(edType)
{
case 'U':
case 'u':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
sumUniversity += salary;
uniCounter++;
}
break;
case 'C':
case 'c':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
sumCollege += salary;
collegeCounter++;
}
break;
case 'H':
case 'h':
Console.Write("\nEnter salary: ");
salary = Double.Parse(Console.ReadLine());
if (salary < 0)
Console.WriteLine("Invalid salary");
else
{
highSchool += salary;
highSchoolCounter++;
}
break;
case 'q':
case 'Q':
  
break;
default:
Console.WriteLine("Not valid education type..Retry");
break;
}
} while (char.ToUpper(edType) != 'Q');
double avg1 = 0, avg2 = 0, avg3 = 0;
if(uniCounter>0)
{
avg1 = sumUniversity / uniCounter;
}
if(collegeCounter>0)
{
avg2 = sumCollege / collegeCounter;
}
if(highSchoolCounter>0)
{
avg3 = highSchool / highSchoolCounter;
}
//Print result
Console.WriteLine("University Average Salary = {0}\nCollege Average Salary = {1}\nHigh School average salary = {2}", avg1.ToString("C"), avg2.ToString("C"), avg3.ToString("C"));
//pause
Console.ReadLine();
}
}
}

//Output

//If you need any help regarding this solution.......please leave a comment..... thanks


Related Solutions

As an educator, you have been approached by the manager to assist with the moving of...
As an educator, you have been approached by the manager to assist with the moving of the unit currently on Floor 6 to Floor 4. This move is going to occur during the day and time that you and your learners are scheduled. The manager would appreciate your participation because with you and your learners, there will be sufficient assistance without having to pay significant overtime. While the learners will be moving the patients in their beds, they also will...
You have been asked to create a program that builds a tower base on the number...
You have been asked to create a program that builds a tower base on the number of items given as input. When the only 1 item is given you create no tower you just place the item on top of the stand. When 2 items are given you build the base of the tower with one foot to the right and one foot to the left. The feet will be in the ground and support the tower. For every additional...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
1) You have been approached by Lakeside Company to be their auditor. They have fired the...
1) You have been approached by Lakeside Company to be their auditor. They have fired the previous audit firm and are now looking for a new firm. Please answer the following questions concerning this potential engagement. a. What are the issues to consider in making this decision? b. Based on your answer in a) above; What is the most important consideration for your firm in making this decision? Why? c. What are the risks that Lakeside, the potential client, faces...
In C Programming Create a payroll program to store and calculate the payroll for a small...
In C Programming Create a payroll program to store and calculate the payroll for a small company as follows: Ask the user for the number of employees and only accept the number if it is between 5 and 40 employees, otherwise prompt the user again and test the input, keep repeating until the user enters an acceptable number. Create an array of floats that is 4 rows and an number of columns equal to the number of employees in the...
Assume that you have been approached by a competitor in Mexico to engage in a joint...
Assume that you have been approached by a competitor in Mexico to engage in a joint venture. The competitor would offer the classroom facilities (so that you would not need to rent classroom facilities), while your employees would provide the teaching. You would split the profits with this business. Discuss how your potential return and your risk would change if you pursue the joint venture.
4. (a) As a stockbroker, you have been approached by a client seeking to establish a...
4. (a) As a stockbroker, you have been approached by a client seeking to establish a diversified portfolio of domestic shares. After identifying the client’s investment needs, you recommend the client use an exchange traded fund (ETF) to achieve her investment objectives. Explain to the client how an ETF will achieve the objective of a diversified share portfolio. (b) The client also wishes to gain an investment exposure to the international share markets. Is it possible to use ETFs to...
You have been asked to create a python program that will ask the user how many...
You have been asked to create a python program that will ask the user how many tickets the user would like to purchase for graduation. The user will then choose the number of tickets needed and the program will list the cost of the tickets, a service fee, tax, and the total of the purchase. Specifications: The program should only accept whole numbers when receiving input for the number of tickets needed. No calculations should be performed if input is...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
C++ please You have been challenged with a menu program before, but this one is a...
C++ please You have been challenged with a menu program before, but this one is a little more complex. You will use loops and you will use an output file for a receipt. Using class notes, write an algorithm for a program which uses a loop system to allow customers to select items for purchase from a list on the screen. (List at least 8 items to choose from on your menu. You choose the items to be listed.). When...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT