1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
struct CorpData
{
string Division;
int firstq;
int secondq;
int thirdq;
int fourthq;
int toal;
int avrg;
};
void placeCursor(HANDLE, int, int);
void displayPrompts(HANDLE);
void getUserInput(HANDLE, CorpData&);
void displayData(HANDLE, CorpData, CorpData);
void Calculate(CorpData&, CorpData&);
int main()
{
CorpData input, value;
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
displayPrompts(screen);
getUserInput(screen, input);
displayData(screen, input, value);
system("pause >nul");
return 0;
}
void placeCursor(HANDLE screen, int row, int col)
{
COORD position;
position.Y = row;
position.X = col;
SetConsoleCursorPosition(screen, position);
}
void displayPrompts(HANDLE screen)
{
placeCursor(screen, 3, 25);
cout << "******* Corporation Form *******" << endl;
placeCursor(screen, 5, 25);
cout << "Division: " << endl;
placeCursor(screen, 7, 25);
cout << "First quarter sales: " << endl;
placeCursor(screen, 9, 25);
cout << "Second quarter sales: " << endl;
placeCursor(screen, 11, 25);
cout << "Third quarter sales: " << endl;
placeCursor(screen, 13, 25);
cout << "Fourth quarter sales: " << endl;
}
void getUserInput(HANDLE screen, CorpData &input)
{
placeCursor(screen, 5, 34);
getline(cin, input.Division);
placeCursor(screen, 7, 45);
cin >> input.firstq;
placeCursor(screen, 9, 46);
cin >> input.secondq;
placeCursor(screen, 11, 45);
cin >> input.thirdq;
placeCursor(screen, 13, 46);
cin >> input.fourthq;
}
void Calculate(CorpData &value, CorpData &input)
{
value.toal = input.firstq + input.secondq + input.thirdq + input.fourthq;
value.avrg = (input.firstq + input.secondq + input.thirdq + input.fourthq) / 4;
}
void displayData(HANDLE screen, CorpData input, CorpData value)
{
placeCursor(screen, 15, 0);
cout << "Division: " << input.Division << endl;
cout << "First Quarter Sales: " << "$" << input.firstq << endl;
cout << "Second Quarter Sales: " << "$" << input.secondq << endl;
cout << "Third Quarter Sales: " << "$"<< input.thirdq << endl;
cout << "Fourth Quarter Sales: " << "$" << input.fourthq << endl;
cout << "Annual Sales: " << "$" << value.toal << endl;
cout << "Average Quarterly Sales: " << "$" << value.avrg << endl;
}
|