CS 31 - Introduction to Computer Science I
Time: Friday 10am-11:50am
Location: Dodd Hall 161
Teaching Assistant: Yihe Deng
Learning Assistant: Ethan Hopkins
Office Hours
Tuesday 9:30am-11:30am on Zoom (zoom link is available on BruinLearn).
Discussion Slides
Quick note on the pipelines that you would typically go through for projects:
Do the coding at your local desktop (Xcode/Visual C++)
You can complete your project just using your own desktop
Linux server (seasnet) is for double checking your results, as grading is done with Linux. Follow the these steps when using the remote server
Connect to UCLA VPN using Cisco Connect.
To copy local files to the remote server, use Terminal and type the following command:
scp directory/to/your/file yourSEASaccount@lnxsrv07.seas.ucla.edu:Desktop
If you don't know the path to your local file, I would recommend copying the file to your Downloads folder. The path should then be Downloads/yourfile.cpp
To actually complie and run the program, you need either ssh with Terminal or Putty if you are using Windows.
Then run the following to set up g31, compile the .cpp source code, and run the program.
setupg31
g31 –o hello hello.cpp
./hello
Quick note on cin.ignore()
cin.ignore() is used with input streams to ignore or skip characters in the input buffer.
The purpose of using cin.ignore() is often to handle the leftover newline character ('\n') in the input stream after a previous input operation, particularly when switching between reading different types of inputs (like from int to string).
Example usage: After reading a numeric input using cin, a newline character is often left in the input buffer. If the next input is a string, this leftover newline character is immediately read as the string input, which is usually not the intended behavior. To prevent this, we use cin.ignore() right after reading the numeric input.
int age;
string name;
cin >> age;
cin.ignore();
geline(cin, name);
e.g. The need for cin.ignore() typically arises when you use getline() after cin for a different input type.
Ignoring multiple characters: You can also use cin.ignore to skip over a specific number of characters in the input buffer or until a specific delimiter is found. For instance, cin.ignore(100, '\n') will ignore up to 100 characters or until a newline character is encountered, whichever comes first.
Further notes on cin and getline():
Behavior of cin: When you use cin to read data, it leaves the newline character ('\n') in the input buffer. This happens because cin reads the data until it encounters a newline character (or whitespace characters), but it doesn't actually consume this newline character from the input buffer.
Behavior of getline(): On the other hand, getline() reads input until it encounters a newline character and it does consume the newline character.
Useful resources for review
Week 5: 02/09/2024 (midterm week)
Week 7: 02/23/2024 (slides)
Week 8: 03/01/2024 (slides)
Week 9: 03/08/2024 (slides)
Week 10: 03/15/2024 (slides)
Useful resources for review
Useful Resources
Lecture notes for MIT's Introduction To C++.