Name:__________________________
SSN:___________________________
The number of points for each problem is listed in curly braces ({points}) after each problem.
Hint: Don't make things to difficult for yourself,
if you are spending a great deal of time on a problem, than chances are
that you have not noticed a KEY point of the problem, and READ the problem
before attempting to solve it. If you answer a similar question to
the one asked, you will not be given credit.
Use the following program for questions 1-4:
#include <iostream>
#include <string>
using namespace std;
void input(string & name, int & num, int &
id);
void output(string name, int num, int id);
int main() {
string userName = "Nobody";
int idNumber = 0;
int employeeSalary = 0;
int employeeNumber = 0;
// get the user's input for the variables...
input(userName, employeeNumber, idNumber,
employeeSalary);
// output what was read in.
output(userName, employeeNumber, idNumber,
employeeSalary);
return 0;
}
void input(string & name, int & num, int &
id) {
char ch;
// Read in each entry, if this is a newline,
ignore the variable
// (leave unchanged).
// We need to remember that
since we are not using cin >>,
// we need to flush the stream.
cout << "Name: " << flush;
// since we have to watch out for the one
character signal,
// that we don't want to change a value, the
newline, read one
// character... only read more if the
value is not a newline.
ch = cin.get();
if (ch != '\n') {
// if the value is not a newline,
then put the character back
// so we can read it as the full
value for name.
cin.putback(ch);
getline(cin, name)
}
// because getline gets the newline, we do
not need to worry
// about stray newlines.
cout << "Employee Number: ";
ch = cin.get();
if (ch != '\n') {
cin.putback(ch);
cin >> num;
cin.get(); // >> leaves '\n's
on the input stream,
// so get rid of it.
}
cout << "Employee Id: ";
ch = cin.get();
if (ch != '\n') {
cin.putback(ch);
cin >> id;
cin.get(); // >> leaves '\n's
on the input stream,
// so get rid of it.
}
void output(string name, int num, int id) {
cout << "The user's name was: " <<
userName << endl;
cout << "The user's number is: " <<
employeeNumber << endl;
cout << "The id number the company uses
to track the employee is: "
<< idNumber
<< endl;
cout << "The employee's salary is: $"
<< employeeSalary << endl;
}
Name: David Samson
ID: Tom
Title: Programmer
Salary: $45000
Would you like to modify this entry?
yes
Name:
ID:
Title:
Salary: $36000
#include <iostream>
#include <string>
using namespace std;
int main() {
return 0;
}