CS 3005: Programming in C++
Questions 3
In this assignment, you will create a program that asks the user three questions, and gives output based on the answers to those questions. No knights should be harmed in the creation of this program.
Some of the code you create in this assignment will be used in the rest of the assignments.
The actual program you will build is rather simple. You should be concentrating on the process of editing, compiling, linking, running, committing and pushing your program. It would be wise to update your set of notes to guide you through this process as you complete future assignments this semester.
Assignment
Create a program, following the programming requirements listed below. This program will ask the user their favorite color, favorite integer number, and favorite floating point number. It will then display lines of output based on the user’s responses to these questions. In particular, each line will contain 3 pieces of information:
- the line number (starting from 1)
- the favorite color
- the favorite floating point number
The number of lines will be controlled by the favorite integer number. If the favorite integer number is 0 or less, then no lines will be displayed.
Potential Session
$ ./questions_3
What is your favorite color? Teal
What is your favorite integer? 6
What is your favorite number? 3.14
1 Teal 3.14
2 Teal 3.14
3 Teal 3.14
4 Teal 3.14
5 Teal 3.14
6 Teal 3.14
Programming Requirements
The following files must be created and stored in the src
directory
of your repository.
Create image_menu.h
This file must include declarations of the following functions:
std::string getString( std::istream& is, std::ostream& os, const std::string& prompt );
int getInteger( std::istream& is, std::ostream& os, const std::string& prompt );
double getDouble( std::istream& is, std::ostream& os, const std::string& prompt );
int askQuestions3(std::istream& is, std::ostream& os);
int assignment1( std::istream& is, std::ostream& os );
Create user_io.cpp
This file must include the implementations of the following functions:
std::string getString( std::istream& is, std::ostream& os, const std::string& prompt );
This function must display theprompt
to the output stream (os
), read a string response from the input stream (is
) and return the string.int getInteger( std::istream& is, std::ostream& os, const std::string& prompt );
This function must display theprompt
to the output stream (os
), read an integer response from the input stream (is
) and return the integer.double getDouble( std::istream& is, std::ostream& os, const std::string& prompt );
This function must display theprompt
to the output stream (os
), read a double precision floating point response from the input stream (is
) and return the double.int askQuestions3(std::istream& is, std::ostream& os);
This function usesgetString
, using the prompt “What is your favorite color? “,getInteger
using the prompt “What is your favorite integer? “, andgetDouble
using the prompt “What is your favorite number? “. It must then repeatedly send the line described above in the assignment description to the output stream. Returns the integer number given by the user. Be sure to read the full description above.
Create controllers.cpp
This file must include the implementations of the following functions:
int assignment1( std::istream& is, std::ostream& os );
This function callsaskQuestions3
andreturn
s the value returned by that function.
Create questions_3.cpp
This file must include the implementations of the following functions:
int main( );
This function should callassignment1
, passing instd::cin
andstd::cout
as the input and output streams to use. It should return the value returned byassignment1
.
Update Makefile
This file must now also include the rules to build the program questions_3
.
The following commands should work correctly. You’ll need to know about the
all
target.
make hello
- builds the hello programmake questions_3
- builds the questions_3 programmake
- builds both the hello and questions_3 programs.
Additional Documentation
Show Off Your Work
To receive credit for this assignment, you must:
- Use git to add, commit and push your solution to your repository for this class.
- Successfully pass all unit tests and acceptance tests
Additionally, the program must build, run and give the correct output.
Last Updated 01/22/2024