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 BunnySight: the program that lets you enter information about a "; std::cout << "bunny sightings on the VIU campus." << std::endl; std::cout << "You will be asked to enter the date, "; std::cout << "the bunny size and colour, and what building it was closest to." << std::endl;Again try compiling/fixing until it compiles cleanly, and now when we run it we should see the message above.
int main() { int day, month, year; // the date the bunny was seen (1-31 for day, 1-12 for month) std::string colour; // the colour of the bunny as a single word, e.g. "brown" std::string size; // the size of the bunny as one of "small", "average", "large" int building; // the number of the building closest to the bunny (e.g. 315) ... the cout's 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 day you saw the bunny (1-31)" << std::endl; std::cin >> day;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 six variables, giving the user a clear description of what they should be entering for each, e.g.
std::cout << "Enter the size of the bunny as either small, average, or large" << std::endl; std::cin >> size;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 sighting:" << std::endl; std::cout << " it was on " << day << "/" << month << "/" << year << std::endl; std::cout << " the bunny was " << colour << " and " << size << std::endl; std::cout << " and was near building " << building << 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 BunnySight: the program that lets you enter information about bunny sightings on the VIU campus. You will be asked to enter the date, the bunny size and colour, and what building it was closest to. Enter the day you saw the bunny (1-31) 10 Enter the month you saw the bunny (1-12) 9 Enter the year you saw the bunny (e.g. 2024) 2024 Enter the colour of the bunny as a single word, e.g. brown blue Enter the size of the bunny as one of small, average, or large large Enter the number of the building nearest the bunny, e.g. 315 300 To summarize your sighting: it was on 10/9/2024 the bunny was blue and large and was near building 300 |