Welcome to CS141 Lab 3 - Linux Fundamentals and Conditional Branches
Today’s lab is structured as follows:
5 Mins - Quiz
10 Mins - Introduction to Linux Terminal and the g++ compiler
25 Mins - Lab exercise on conditional statements
10 Mins - Grading
Linux Tutorial
This is intended to be done on the projector alongside the instructor
Login to the Lab Machine using your CS Account Username and Password
Make a directory for CS141 by typing
>>mkdir CS141
See the directory you are in by typing
>>pwd
See the contents of that directory by typing
>>ls
Navigate to the CS141 directory by typing
>>cd/CS141
Can you make a directory for Lab 3?
Download the code stub provided for the lab exercise and store in the directory for Lab 3 using the GUI.
Navigate to your Lab 3 folder
Compile the code by typing
>>g++ lab2.cpp
The result is an executable file containing your program. Run the program by typing
>>./a.out
Lab Exercise
Playing Rock-Paper-Scissors is a critical skill in today’s world. The sport involves 2 players and three hand signals, rock (a closed fist), paper ( an open palm), and scissors (similar to a peace sign). A player is a winner when their symbol “beats” the opposing players. Rock-Paper-Scissors can be used to settle who gets the last slice of pizza or the rights to sell a multi-million dollar art collection.
The winning combinations are as follows:
For those just learning the game, losses can be disappointing. Your task is to program a game vs the computer where the USER ALWAYS WINS!
Start with the stub of code provided.
Program Execution Looks Like:
Welcome to CS 141 Rock-Paper-Scissors where
the user always wins and everything is awesome
Enter 1 for Rock
Enter 2 for Paper
Enter 3 for Scissors
Enter 4 to Quit
Select your implement: 1
Computer Selects: Scissors
You Win!
Select your implement: 2
Computer Selects: Rock
You Win!
Select your implement: 4
Bye!
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
cout << "Welcome to CS 141 Rock-Paper-Scissors where\n" <<
"the user always wins and everything is awesome" << endl;
cout << endl << "Enter 1 for Rock\n" << "Enter 2 for Paper\n" <<
"Enter 3 for Scissors\n" << "Enter 4 to Quit" << endl <<
endl;
int userSelection = 0;
while(userSelection != 4){
cout << "Select your implement: ";
cin >> userSelection;
// Your Code Goes Here
// Step 1 : Implement with if-else statements
// Step 2 : Implement with a switch-case statement
cout << "You Win!" << endl;
}
cout << "Bye!\n";
return 0;
}
Points:
0. Did not show up or did not code with a partner
Compile code using g++ editor in the terminal window
Implement the game using if-else statements
Implement the game using a switch-case statement