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
|
#include <iostream>
#include <string>
using namespace std;
void GetName(const string, const int, string&);
void DisplayNames(string, string, string);
void main()
{
const int MAX_FIRST = 30;
const int MAX_LAST = 25;
const int MAX_LOCATION = 20;
const int MAX_MONTHS = 12;
const string FIRST_QUESTION = { "First Name (25 chars max, type \"quit\" to stop): " };
const string LAST_QUESTION = { "Last Name (30 chars max, type \"quit\" to stop): " };
const string LOCATION_QUESTION = { "Location (20 chars max, type \"quit\" to stop): " };
string firstName = "";
string lastName = "";
string locationName = "";
char rating[MAX_MONTHS];
int ratingNumber[MAX_MONTHS];
while (true)
{
GetName(LAST_QUESTION, MAX_LAST, lastName);
GetName(FIRST_QUESTION, MAX_FIRST, firstName);
GetName(LOCATION_QUESTION, MAX_LOCATION, locationName);
DisplayNames(lastName, firstName, locationName);
}
}
void GetName(const string question, const int MAX, string &name)
{
int count;
do
{
cout << question;
cin >> name;
name[0] = toupper(name[0]);
for (count = 1; count < name.length(); count++)
{
name[count] = toupper(name[count]);
}
} while (name.length() > MAX || name.empty());
}
void DisplayName(string last, string first, string location)
{
cout << "Last Name: " << last << endl;
cout << "First Name: " << first << endl;
cout << "Location: " << location << endl;
}
|