Question: Objective For this week's assignment, your goal is to start becoming familiar with the basics of C++ and get accustomed to our CCSF computer systems
Objective
For this week's assignment, your goal is to start becoming familiar with the basics of C++ and get accustomed to our CCSF computer systems and homework submission process.
Instructions
I've written a small C++ program below. The program asks the user how many asterisks it should print out. The user responds with a number, and then the program prints the asterisks. Finally the program asks the user if it should start over, and repeats as many times as the user wants.
Read the program and try to understand what it is doing. In the likely event that your experience is in a language other than C++, you may not understand all of the specific C++ syntax, and that's ok! But some basic things, like the while loop and for loop, should look somewhat familiar. We will talk about these concepts in more detail in the coming weeks; but for now, here is a crash course:
- cin gets input from the user into a variable
- cout outputs text to the terminal window
- the comment, #include statement, using namespace statement, and int main() need to be in all of our programs
After reviewing the program, set the program aside and type in an identical program and compile it. You don't need to use the same variable names and formatting, but be careful with your indentation, and make sure that the flow of control is identical.
// Assignment 1: Your name here // This program prints out as many asterisks as the user wants. #includeusing namespace std; int main() { int count; char goAgain = 'y'; while (goAgain != 'n') { cout << "How many asterisks?: "; cin >> count; for (int i = 0; i < count; i++) { cout << "*"; } cout << endl; cout << "Go again? (y/n): "; cin >> goAgain; } return 0; }
Submission
See "Using hills to write, compile, run, and submit C++ programs" in the Software needed for this course page in this module. This provides a video and step-by-step instructions on how to write your program, compile it, run it, and submit your program and sample output using nano and g++ on hills. Copy and paste your sample output at the bottom of your program file in a multi-line comment, it should look something like this:
/* SAMPLE OUTPUT [mluttrel@hills ~]$ ./a.out How many asterisks?: 3 *** Go again? (y/n): y How many asterisks?: 10 ********** Go again? (y/n): y How many asterisks?: 1 * Go again? (y/n): n [mluttrel@hills ~]$ */
Submit your C++ source code and sample output all in one file via Canvas. The file format must be plain text, with a .cpp extension.. It must not be a rich format like .rtf, .doc, .pdf, etc.
Make sure to submit by the deadline! See the syllabus for the policy on late assignment submissions.
Yes, I have given you the solution for this assignment question! Don't worry, I won't do that in future assignments!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
