Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CIS-2207 Week1 Assignment1 Company Devisions
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <iostream> #include <string> #include <iomanip> using namespace std; // global variables struct devision { string name; double firstQtr; double secondQtr; double thirdQtr; double fourthQtr; double total; double avg; }; // Function prototypes void collectSales(double [], string); void storeSales(devision *, double []); void displayDevision(devision); int main() { // variables devision north, east, south, west; double quarterInputs[4] = {0.0, 0.0, 0.0, 0.0}; // instructions didn't state that the names needed to be supplied by the user north.name = "North"; east.name = "East"; south.name = "South"; west.name = "West"; collectSales(quarterInputs, north.name); storeSales(&north, quarterInputs); //cout << "\n dvsn.firstQtr = " << north.firstQtr << endl; //used for debugging displayDevision(north); collectSales(quarterInputs, east.name); storeSales(&east, quarterInputs); displayDevision(east); collectSales(quarterInputs, south.name); storeSales(&south, quarterInputs); displayDevision(south); collectSales(quarterInputs, west.name); storeSales(&west, quarterInputs); displayDevision(west); } // end main void collectSales(double qtrInpts[], string dvsn) { // collect quarter sales from user for(int i = 0; i < 4; i++) { cout << "\nEnter sales for devision " << dvsn << " quarter " << i+1 << ": "; while(!(cin >> qtrInpts[i])) // still need to validate against negatives { cout << "\n Please enter a valid sales value: " << endl; } //cout << "\n qtrInpts[" << i << "] = " << qtrInpts[i] << endl; //used for debugging } } void storeSales(devision *dvsn, double qtrInpts[]) { //cout << "\n qtrInpts[] = " << qtrInpts[0] << endl; //used for debugging // assign collected sales values dvsn->firstQtr = qtrInpts[0]; dvsn->secondQtr = qtrInpts[1]; dvsn->thirdQtr = qtrInpts[2]; dvsn->fourthQtr = qtrInpts[3]; dvsn->total = (qtrInpts[0] + qtrInpts[1] + qtrInpts[2] + qtrInpts[3]); dvsn->avg = (dvsn->total / 4); } void displayDevision(devision dvsn) { cout << endl << "" << dvsn.name << endl << "-------\n" << "First Quarter = $" << dvsn.firstQtr << endl << "Second Quarter = $" << dvsn.secondQtr << endl << "Third Quarter = $" << dvsn.thirdQtr << endl << "Fourth Quarter = $" << dvsn.fourthQtr << endl << "Total = $" << dvsn.total << endl << "Average = $" << dvsn.avg; } /* In C++ please write a program will: 1) Write a Structure that will contain the following data about a company's divisions: Division Name (such as West, East, North or South) First-Quarter Sales Second-Quarter Sales Third-Quarter Sales Fourth-Quarter Sales Total Annual Sales Average Quarterly Sales -The program will use four variables for this structure. -Each variable will represent one of the following corporate divisions: East, West, North and South. -The user will be asked for the four quarters' sales figures for each division. -Each division's total and average sales will be calculated and stored in the appropriate member of each structure variable. These figures will then be displayed on the screen. -Validation: Do not accept negative numbers for any sales figures. */
run
|
edit
|
history
|
help
0
std override
Multiple inheritance of empty classes - sizeof
copy
hangman
C++ standard library formatted input hexadecimal float without prefix or exponent test case
#9
print adapted struct
return reference (msvc)
Buggy Strcat
primitive type copy constructor