Program Description: Basic User Interface This program creates the basic user in
ID: 3757804 • Letter: P
Question
Program Description: Basic User Interface This program creates the basic user interface code for that can be used in the following week’s iLab assignments. The assignment will help you get started using the programming environment and some practice with coding. You will also be able to re-use much, if not all, of the code in later assignments. In this program, you will create the following methods:
1. Main method, which is the starting point for the execution of the program.
2. DisplayApplicationInformation, which will provide the program user some basic information about the program.
3. DisplayDivider, which will provide meaningful output separator between different sections of the program output.
4. TerminateApplication, which provides a program terminate message and terminates the application.
5. GetInput, which is a general function that will prompt the user for a specific type of information, then return the string representation of the user input.
Using these methods, you will construct a program that prompts the user for the following:
1. Your name, which will be a string data type
2. Tour age, which will be an integer data type
3. The gas mileage for your car, which will be a double data type
Also, note that the program should contain a well-documented program header and the methods will be created in the classes as defined in the pseudocode.
Explanation / Answer
Pseudocode:
Start main
//declare variables
input as string
name as string
age as integer
mileage as double
call DisplayApplicationInformation
call DisplayDivider(“Start Program”)
call DisplayDivider(“Get Name”)
set name = GetInput(“Your Name”)
display “Your name is: “ + name
call DisplayDivider(“Get Age”)
set input = GetInput(“Your Age”)
set age = convert input to integer
display “Your age is: “ + age
call DisplayDivider(“Get Mileage”)
set input = GetInput(“Gas Mileage”)
set mileage = convert input to double
//display mileage to 2 decimal places
display “Your car MPG is: “ + mileage
call TerminateApplication
end main program
procedure DisplayApplicationInformation
display “Welcome the Basic User Interface Program”
display “CIS247, Week 1 Lab”
display “Name: YOUR NAME”
display “This program accepts user input as a string, then makes the appropriate data conversion”
end procedure
procedure DisplayDivider(string outputTitle)
display “**************** “ + outputTitle + “****************”
end procedure
function GetInput(string inputType) as string
strInput as string
display “Enter the “ + inputType
get strInput
return strInput
end function
procedure TerminateApplication
display “Thank you for using the Basic User Interface program”
exit application
end procedure
Program:
#include <iostream>
#include <string>
void DisplayApplicationInformation();
void DisplayDivider(string message);
string GetInput(string message);
void TerminateApplication();
int main()
{
string name;
string input;
int age;
double mileage;
DisplayApplicationInformation();
DisplayDivider("Start Program");
DisplayDivider("Get Name");
name = GetInput("Your Name");
cout << "Your name is " << name <<endl;
DisplayDivider("Get Age");
input = GetInput("Your Age");
age = atoi(input.c_str());
cout << "Your age is " << age <<endl;
DisplayDivider("Get Mileage");
input = GetInput("Your mileage");
mileage = atof(input.c_str());
cout << "Your car MPG is " << mileage <<endl;
TerminateApplication();
}
void DisplayApplicationInformation()
{
cout << "Welcome the Basic User Interface Program " << endl;
cout << "CIS247, Week 1 Lab" << endl;
cout << "Name: YOUR NAME" << endl;
cout << "This program accepts user input as a string, then makes the appropriate data conversion" << endl;
}
void DisplayDivider(string outputTile)
{
cout << "**********************" << outputTile << "******************" << endl;
}
string GetInput(string inputType)
{
string input;
cout << "Enter the "<< inputType <<": ";
cin >> input;
return input;
}
void TerminateApplication()
{
cout << "Thank You For Using the Basic User Interface Program";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.