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
|
#include <iostream>
#include <windows.h> // Needed to set cursor positions
#include <string>
using namespace std;
struct Birthday
{
string name;
char birthday[1];
char birthyear[1];
int result;
int numofpres;
int moneyavail;
};
void placeCursor(HANDLE, int, int); // Function prototypes
void displayPrompts(HANDLE);
void getUserInput(HANDLE, Birthday&);
void displayData(HANDLE, Birthday);
int main()
{
Birthday input;
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
displayPrompts(screen);
getUserInput(screen, input);
displayData(screen, input);
system("pause >nul");
return 0;
}
void placeCursor(HANDLE screen, int row, int col)
{ // COORD is a defined C++ structure that
COORD position; // holds a pair of X and Y coordinates
position.Y = row;
position.X = col;
SetConsoleCursorPosition(screen, position);
}
void displayPrompts(HANDLE screen)
{
placeCursor(screen, 3, 25);
cout << "******* Birthday Form *******" << endl;
placeCursor(screen, 5, 25);
cout << "Name: " << endl;
placeCursor(screen, 7, 25);
cout << "Birthday: " << endl;
placeCursor(screen, 7, 37);
cout << "/" << endl;
placeCursor(screen, 9, 25);
cout << "How many presents do you want?: " << endl;
placeCursor(screen, 11, 25);
cout << "How much money can you spend on your party?: " << endl;
}
void getUserInput(HANDLE screen, Birthday &input)
{
placeCursor(screen, 5, 31);
getline(cin, input.name);
placeCursor(screen, 7, 34);
cin.getline(input.birthday,1);
placeCursor(screen, 7, 38);
cin.getline(input.birthyear, 1);
placeCursor(screen, 9, 56);
cin >> input.numofpres;
placeCursor(screen, 11, 69);
cin >> input.moneyavail;
}
void displayData(HANDLE screen, Birthday input)
{
placeCursor(screen, 15, 0);
cout << "Here is the data you entered.\n" << endl;
cout << "Name : " << input.name << endl;
cout << "Birthday : " << input.birthday << "/";
cout << input.birthyear << endl;
cout << "Presents Wanted : " << input.numofpres << endl;
cout << "Money Available : " << input.moneyavail << endl;
}
|