In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis.
Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values.
In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US")));
Tasks:
Use arrays for store salesperson names, initials, and accumulated sales values:
Array of type double declared to store accumulated sales values
1. Searched your code for a specific pattern: double\s*\[\]
Array of type char declared to store allowed initials
1. Searched your code for a specific pattern: char\s*\[\]
Array of type string declared to store salesperson names
1. Searched your code for a specific pattern: string\s*\[\]
The program's main functionality remains unchanged from Chapter 5, Programming Exercise 5.
1. Successful Output 1
Expected Output
50.00 25.00 60.00 135.00
2. Successful Output 2
Expected Output
90.00 10.00 50.00 150.00
3. Program accepts both upper and lower case value for a salesperson's initial
Expected Output
Danielle\ssold\s*\$15\.00
Edward\ssold\s*\$0\.00
Francis\ssold\s*\$0\.00
4. The program displays an error message for invalid initials
Sorry - invalid salesperson
Here is the code submitted in the previous assignment that it wants main functionality to not change:
using System;
using static System.Console;
using System.Globalization;
class HomeSales
{
static void Main()
{
// Write your main here.
string initial = "";
int dsale = 0;
int esale = 0;
int fsale = 0;
int total = 0;
while(initial != "z")
{
Write("Enter a sales person initial: ");
initial = ReadLine().ToLower();
if(initial == "d" || initial == "e" || initial == "f")
{
Write("Enter amount of sale: ");
int amount = Convert.ToInt32(ReadLine());
if(initial =="d")
dsale += amount;
else if(initial =="e")
esale += amount;
else if(initial == "f")
fsale += amount;
}
else {
if(initial != "z")
{
WriteLine("Sorry - invalid salesperson");
}
}
}
total = dsale + esale + fsale;
WriteLine("Danielle sold {0}", dsale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Edward sold {0}", esale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Francis sold {0}", fsale.ToString("C",CultureInfo.GetCultureInfo("en-US")));
WriteLine("Total sales were {0}", total.ToString("C",CultureInfo.GetCultureInfo("en-US")));
if(dsale > esale && dsale > fsale)
{
WriteLine("Danielle sold the most");
}
else if(esale > dsale && esale > fsale)
{
WriteLine("Edward sold the most");
}
else if(fsale > dsale && fsale > esale)
{
WriteLine("Francis sold the most");
}
else
{
WriteLine("There was a tie");
}
}
}
// C# program to create an application for Home sales
using System;
using static System.Console;
using System.Globalization;
class HomeSales
{
static void Main()
{
// Write your main here.
// convert initial to char from
string
char initial = ' ';
// create arrays of size 3
// create an array to store the
initials
char[] initials = new
char[3];
// create an array to store the
sales
double[] sales = new
double[3];
// create an array to store the
names
string[] names = new
string[3];
// initialize all sales to 0
for(int
i=0;i<sales.Length;i++)
sales[i] =
0;
// set the initials and names of
the 3 salesperson
initials[0] = 'd';
initials[1] = 'e';
initials[2] = 'f';
names[0] = "Danielle";
names[1] = "Edward";
names[2] = "Francis";
double total = 0; // set total to
0
int index;
// loop that continues until the
input initial is z
while(initial != 'z')
{
// input the
initial
Write("Enter a
sales person initial: ");
initial =
ReadLine().ToLower()[0];
// loop to
get the index of the salesperson with the given initial
for(index=0;index<initials.Length;index++)
{
if(initials[index] == initial)
{
break;
}
}
// if initial is
found
if(index !=
initials.Length)
{
// input the sales amount and add it to the
sales of the salesperson at index
Write("Enter amount of sale: ");
double amount =
Convert.ToDouble(ReadLine());
sales[index] += amount;
}
else {
// initial not found, check if user wants to
exit
if(initial != 'z')
{
// if user doesn't want to
exit, display error message
WriteLine("Sorry - invalid
salesperson");
}
}
}
// loop to calculate the total
sales and display the sales of each salesperson
for(index = 0;index <
sales.Length; index++)
{
total +=
sales[index];
WriteLine("{0}
sold {1}", names[index],
sales[index].ToString("C",CultureInfo.GetCultureInfo("en-US")));
}
// display the total sales
WriteLine("Total sales were {0}",
total.ToString("C",CultureInfo.GetCultureInfo("en-US")));
// determine which salesperson sold
the most
if(sales[0] > sales[1]
&& sales[0] > sales[2])
{
WriteLine("{0}
sold the most",names[0]);
}
else if(sales[1] > sales[0]
&& sales[1] > sales[2])
{
WriteLine("{0}
sold the most",names[1]);
}
else if(sales[2] > sales[0]
&& sales[2] > sales[1])
{
WriteLine("{0}
sold the most",names[2]);
}
else
{
WriteLine("There
was a tie");
}
}
}
//end of program
In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now,...
In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format...
c# Instructions In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System. Globalization; at the top of your...
Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold by each salesperson. After the user types Z or zfor an initial, display...
Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively. The class contains an auto-implemented property Name that holds a contestant’s name. The class contains fields for a talent code (talentCode) and description (talent)....
In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4. Now, modify the program so that the user must enter a month value from 1 through 12....
In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the user for contestant data for this year’s Greenville Idol competition. Now, save all the entered data to a Greenville.ser file that is closed when data entry is complete and then reopened and read in, allowing the user to view lists of contestants with requested talent types. The program should output the name of the contestant, the talent, and the fee. using System; using static...
Please Help in C#, Let me know if you have any questions. Please make sure the program passes the checks Checks: Question: My code works, it just this needs to be added there which I don't know what I need to do. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output...
This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...
I wrote this code but there’s an issue with it : #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; class Borrower { private: string ID, name; public: Borrower() :ID("0"), name("no name yet") {} void setID(string nID); void setName(string nID); string getID(); string getName(); }; void Borrower::setID(string nID) { ID = nID; } void Borrower::setName(string nname) { name = nname; } string Borrower::getID() { return ID; } string Borrower::getName() { return name; } class Book { private: string...
Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...