Question

C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to...

C++ and Using Microsoft Visual Studio.

Write 2 programs:

One program will use a structure to store the following data on a company division:

  • Division Name (East, West, North, and South)
  • Quarter (1, 2, 3, or 4)
  • Quarterly Sales

The user should be asked for the four quarters' sales figures for the East, West, North, and South divisions. The data for each quarter for each division should be written to a file.

The second program will read the data written by the first program. The program should calculate and display the following figures:

  • Total corporate sales for each quarter
  • Total yearly sales for each division
  • Total yearly corporate sales
  • Average quarterly sales for the divisions
  • The highest and lowest quarters for the corporation

Input Validation: Do not accept negative numbers for any sales figures.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
struct CompanyDivision
{
char name[6];
double qtr_sales[4];
double annual_sales;
double avg_qtr_sales;
public:
CompanyDivision(const char* _name)
{
strncpy(name, _name, 5);
name[5] = '\0';
for (short i = 0; i < 4; i++ )
{
cout << name << " Q" << (i+1) << " Sales: ";
do
{
cin >> qtr_sales[i];
}
while (qtr_sales[i] < 0);
annual_sales += qtr_sales[i];
}
avg_qtr_sales = annual_sales / 4;
}
void print()
{
cout << " Division Name: " << name << '\n'
<< " First-Quarter Sales: " << qtr_sales[0] << '\n'
<< " Second-Quarter Sales: " << qtr_sales[1] << '\n'
<< " Third-Quarter Sales: " << qtr_sales[2] << '\n'
<< " Fourth-Quarter Sales: " << qtr_sales[3] << '\n'
<< " Total Annual Sales: " << annual_sales << '\n'
<< "Average Quarterly Sales: " << avg_qtr_sales << '\n';
}
};
int main()
{
CompanyDivision n ( "North" );
CompanyDivision s ( "South" );
CompanyDivision e ( "East" );
CompanyDivision w ( "West" );
cout << '\n';
e.print();
cout << '\n';
w.print();
cout << '\n';
n.print();
cout << '\n';
s.print();
return 0;
}

2)


#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int LENGTH = 4;
struct CorprateData
{
static string Division[LENGTH];
double Qtr[LENGTH];
double QtrlySales;
};
string CorpData::Division[LENGTH] = {"East", "West", "North", "South"};
int main()
{
CorpData Sales;
double TotCorpQtr[LENGTH] = {0,0,0,0};
double TotYrDiv,   
TotYrCorp,   
Highest,
Lowest;
TotYrCorp = TotYrDiv = 0;
fstream File("salefigures.txt", ios::in | ios::binary);
if (!File)
{
cout << "Error opening file.\n";
return 0;
}
cout << fixed << showpoint << setprecision(2);
cout << "\nCorporate Sales Data Report\n"<< "---------------------------\n";
cout << "\nTotal sales by division:\n";
for (int d = 0; d < LENGTH; d++)
{
File.read(reinterpret_cast<char *>(&Sales), sizeof(Sales));
cout << Sales.Division[d] << ":\n";
cout << " Total yearly Sales: $";
for (int q = 0; q < LENGTH; q++)
{
TotYrDiv += Sales.Qtr[q];
TotCorpQtr[q] += Sales.Qtr[q];
}
cout << TotYrDiv << endl;
cout << " Average quarterly sales: $" << TotYrDiv/4 << endl;
TotYrCorp += TotYrDiv;
}
cout << "\nTotal corporate sales for each quarter:\n";
for (int i = 0; i < LENGTH; i++)
{
cout << "Quarter " << (i + 1) << ": $" << TotCorpQtr[i] << endl;
}
cout << "\nTotal yearly corporate sales: $" << TotYrCorp << endl;
Highest = Lowest = TotCorpQtr[0];
for (int i = 1; i < LENGTH; i++)
{
if (TotCorpQtr[i] > Highest)
Highest = TotCorpQtr[i];
if (TotCorpQtr[i] < Lowest)
Lowest = TotCorpQtr[i];
}
cout << "The highest quarter for the corporation: " << Highest << endl;
cout << "The lowest quarter for the corporation: " << Lowest << endl;
File.close();
return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CProgramming using Dev C ++ #include <stdio.h> PLEASE NO math.h Corporate Sales Data Report Write a...

    CProgramming using Dev C ++ #include <stdio.h> PLEASE NO math.h Corporate Sales Data Report Write a program that read creates a structure for a company's divisions. The structure should have: Division name (North, South, East, West, and Central) Quarter (1, 2, 3, or 4) Quarterly sales · Your job is to write a program that will create a two-dimensional array of 5 rows (divisions) and 4 columns (quarters). The program should ask the user to enter in all four quarters...

  • Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast,...

    Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main. double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid. void...

  • Question 23 Complete the programs by adding the lines or parts of lines that have been...

    Question 23 Complete the programs by adding the lines or parts of lines that have been omitted, or show output. <<<<<<<<<<<<<<<<<<<<<<<<    >>>>>>>>>>>>>>>>>>>>>>>>> Corporate Sales Data Output #include <iostream> #include <fstream> using namespace std; // Constant for array size const int SIZE = 12; // Declaration of the Division structure struct Division { Blank 1 // Division name A. Add code in this box Blank 2 // Quarter number B. Add code in this box Blank 3 // Quarterly sales...

  • Help. Write a C++ program that determines which of a company's four divisions (North, South, East,...

    Help. Write a C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter. It should include three functions at a minimum: float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division. void validate() is...

  • using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get...

    using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get a Factorial (using a loop) 2. perform addition and subtraction 3.allow the user to quit the program

  • Write an encryption and decryption program that displays properly in Microsoft Visual Studio using c++. Encrypt...

    Write an encryption and decryption program that displays properly in Microsoft Visual Studio using c++. Encrypt each digit by adding 7 and taking the remainder after division by 10. After encrypting each digit, swap the first and third then swap the second and fourth. Decryption should reverse the process. Program must input a single integer. Program must do encode and decode in one file.         Example Program Session (yours must look like this): Encode (1) Decode (2): 1 Enter...

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • Directions: Create a structure that contains the following data: DivisionName First-QuarterSales Second Quarter Sales Third Quarter...

    Directions: Create a structure that contains the following data: DivisionName First-QuarterSales Second Quarter Sales Third Quarter Sales Fourth Quarter Sales Total Sales Average Sales Create an enumerated data type of {North,South,East,West} Create an array of this structure with one instance for each enumerated data type listed above. Write a C++ program that will create a menu driven program with the following options: Menu Options: A) Add Data B) Compute Total Sales and Avg Sales C) Display Data D) Division Highest...

  • Using Microsoft Visual Studio 2017 C++, write a C++ program to calculate to analyze the data...

    Using Microsoft Visual Studio 2017 C++, write a C++ program to calculate to analyze the data from the number of visitors to Sleeping Bear Dunes in Michigan in 2015. Requirements Read the data from the Months.txt and Visitors.txt files. The text files are provided for you to download. The data was obtained from the National Park Service website. Design the program so the user enters a menu item and the following is displayed Display the chart below Totals and display...

  • I need help building a program on microsoft visual studio using c++ language. implement a program...

    I need help building a program on microsoft visual studio using c++ language. implement a program called "charword_freq.cpp" to determine the number of words and the number of occurrences of each letter in a block of text stored in a data file called “mytext.dat”. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of a line. You can assume that the input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT