Lab Assignment 15 (1)

docx

School

Richland Community College *

*We aren’t endorsed by this school

Course

1436

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

1

Uploaded by AmbassadorEagleMaster689

Report
COSC 1436 Lab Assignment 15 – User Defined Functions NOTE: All programs that you write must have comments at the top with the program name, your name, and a sentence describing what the program will do. 1. Create a new program called Lab15A that will play a game of “Rock-Paper-Scissors” with the user. For the purposes of our game 0=rock, 1=paper & 2=scissors) a. Write an integer function (no parameters) that will return a random number between 0 and 2. (This will be the computer’s play.) Don’t forget you’ll need to include <ctime> and <cstdlib> , and use the following 2 statements: srand(time(0)); randomNum = rand() % 3; After generating the random number, use an if-else if structure to print whether the computer chose rock, paper, or scissors. b. Write a void function that will accept 2 integer parameters, the program’s choice and the user’s choice. In this function use the rules of rock-paper-scissors to determine who won. It should then print the winner. (Game rules: rock beats scissors, scissors beat paper, paper beats rock) c. In the main function: i. Ask the user to enter 0, 1 or 2 for their choice. When you ask, tell them what each digit stands for. ii. Use an if-else if structure to print what the user chose: rock, paper, or scissors. iii. Call the function to get the program’s choice. iv. Call the function to decide the winner (sending the two game choices as parameters). d. Test your program several times to make sure it works for all combinations. 2. Write a program called Lab15B that will have the following. a. An int function named sumDigits with 3 int reference parameters that will return the sum of the last digits in all 3 numbers. (Ex – if the numbers were 35, 21, & 42, the sum would be 5 + 1 + 2 = 8) (Remember that num % 10 will give the last digit of num.) It should also multiply the 3 numbers by 10 afterwards. b. In your main function write a while !eof loop and inside the loop: i. Read 3 integers from the text file (Input15B.txt). (You should have 3 int variables to hold these values and read all 3 of them together.) ii. Print the 3 numbers on one line. iii. Call the sumDigits function sending the 3 values and print the returned value. iv. Print the 3 numbers again (on one line) and a blank line.
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help