NOTE THAT I'LL BE DISTRIBUTING YOUR CSCI LOGIN IDS IN
THIS LAB you will be unable to login on our linux servers to work on your labs until you have this information |
Instructions on how to change your password later, or how to deal with a forgotten password, are provided on the technotes page. |
For those of you who have taken CSCI 159 previously:
We're going to be creating a csci159 directory in your account, but you may already
have one left over from the fall. If so, we'll rename your old one so you don't run
into conflicts with our new one. To do so, enter the command
mv csci159 old159 |
What is the makefile doing right now? The instructor has created a special directory containing the starting files for lab 1, including starter code and its own makefile, which in turn allows you to automatically compile and submit your C++ code for lab 1. If you'd like a look at a makefile's content you can dump it onto the screen using the cat command and the filename, e.g. cat make159 If you're curious about the workings of git for assignment submission (i.e. what the makefile is doing for you) there is a short rundown linked from the technotes page. |
make recompiles lab1.cpp to create a new lab1x using the g++ compiler,
using a command such as g++ -Wall -Wextra lab1.cpp -o lab1x |
As an alternative to opening and closing pico all the time, you can open a second terminal window, do a "cd csci159/lab1" in that one to make sure they're both in the same directory, then run pico in one and type your linux make and ./lab1x commands in the other. |
Each time you do a "make submit" git is used to store the current state of the directory and copy it to the instructor-accessible location. It only works if you're in the correct lab directory, e.g. csci159/lab1 today, and the instructor can only see changes after you submit them, so be sure to do a make submit after your final set of changes for any lab. |
Always remember to logout, not lock screen, when you leave.
1. if you forget to logout then whoever comes in next could use your account, which get ugly. 2. if you lock screen instead of logout then you're tying up the machine for whoever comes in next, and instructors can get quite grumpy if they have a full lab section and a handful of machines are locked. |
#include <iostream> int main() { std::cout << "Welcome to lab1!" << std::endl; return 0; } |
#include <iostream> #include <string>Change the file content, save, then try recompiling in the terminal window
std::cout << "Welcome to CityPicker: the program that lets you enter information about "; std::cout << "your favourite city." << std::endl; std::cout << "You will be asked to enter the name of the city, "; std::cout << "it's approximate population, and the year you last visited." << std::endl; std::cout << std::endl;Again try compiling/fixing until it compiles cleanly, and now when we run it we should see the message above.
int main() { std::string cityname; // the name of your favourite town/city int population; // your estimate for the population of the city int year; // the year you last visited the city ... the cout's from the previous step would be down here ...Again try compiling/fixing until it compiles cleanly other than warnings about unused variables (those will go away as we actually get the user to input some data).
std::cout << "Enter the name of your favourite city "; std::cout << "(use underscores instead of spaces, e.g. Little_Rock)" << std::endl; std::cin >> cityname;These will go below our earlier cout (so they see the program description *then* it starts asking for data) but above the return 0 (since that effectively ends a run of the main routine). Do similarly for each of the variables, giving the user a clear description of what they should be entering for each, e.g.
std::cout << "Enter the year you last visited " << cityname << std::endl; std::cin >> year;As usual, compile and fix until it compiles ok. (Notice the warnings for the variables have changed, now it tells us we've set values for them but aren't using them. This will be fixed in the next step.)
std::cout << "To summarize your choice:" << std::endl; std::cout << " it was the city of " << cityname << std::endl; std::cout << " population " << population << std::endl; std::cout << " and you last visited in " << year << std::endl;Compile and fix (as usual), and hopefully the program should behave as expected when run: giving the user a description of the program, prompting the user for each part of the sighting information and reading it in, then displaying all the information back to the user at the end. Keep tweaking and fixing the program until you're satisfied it is working correctly and you're happy with the appearance of the output.
Welcome to CityPicker: the program that lets you enter information about your favourite city. You will be asked to enter the name of the city, it's approximate population, and the year you last visited. Enter the name of your favourite city (use underscores instead of spaces, e.g. Little_Rock) Port_Douglas Enter the year you last visited Port_Douglas 1998 Enter your guess for the current population of Port_Douglas 4000 To summarize your choice: it was the city of Port_Douglas population 4000 and you last visited in 1998 |