CS161 – In this assignment you’ll get some practice with some of the tools we’ll be using throughout the course. These instructions will assume that you have followed the tutorials in the “Tools You Will Need” page. (Solution)

$ 29.99
Category:

Description

#include <iostream>
#include <string>

// a simple example program int main()
{ std::string faveAnimal;
std::cout << “Please enter your favorite animal.” << std::endl; std::cin >> faveAnimal;
std::cout << “Your favorite animal is the ” << faveAnimal; std::cout << “.” << std::endl;

return 0;
}
Add a comment block at the top as discussed in the Code Style Guidelines. Now save the file. Type ls to verify that this directory now contains a file named animal.cpp. Next type g++ animal.cpp -o animal. This will compile your source file and create an executable file named “animal”. The -o flag lets you choose a name for the executable file. If you instead just type g++ animal.cpp, the name of the executable file will be “a.out”. It is important that you do not accidentally give your executable file the same name as the source file. If you do that, then your executable file will replace your source file and your source file will be gone (and you will be sad). Now type in ./animal.
The program should now ask you to enter the name of your favorite animal, and after you do, it will print out “Your favorite animal is the <whatever you typed>.” Notice that this program only reads the first word of the input, so if the animal name contains any spaces, the full name won’t be printed out.
Now open up the TEACH website, find submission “week1” for your section of the course, and submit your source file there.

Reviews

There are no reviews yet.

Be the first to review “CS161 – In this assignment you’ll get some practice with some of the tools we’ll be using throughout the course. These instructions will assume that you have followed the tutorials in the “Tools You Will Need” page. (Solution)”

Your email address will not be published. Required fields are marked *