Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Team Competition
- Here is a fun game as the semester starts to wrap up! Your team's job is to find out what a mystery program does.
- If a team thinks they have the answer, have one designated member notify Justin and explain to me what it does.
- For the sake of no other teams overhearing, Justin and the member will talk outside the lab for them to explain.
- If they get it correct, their team wins.
- If not, I will send them back to their group to keep working with their team to figure out the program.
- What's the prize you might be asking? Bragging rights.
- RULES
- 1) All teams have 15 minutes. If no one gets it in that time, then I explain what the program does and no one gets bragging rights,
- that sounds like no fun :(
- 2) You must be able to explain to me in detail what the program does! Not just bits and pieces or a vague explanation.
- - A GOOD METRIC is if you can explain generally what the program is doing, along with what function1 and function2 do.
- - YOU DON'T HAVE TO EXPLAIN THE FLUSH INPUT FUNCTION
- 3) Each team has 2 attempts to explain the program to me. If they use all 2 and don't get it on either, they are disqualified.
- - I won't pull any punches. If you're wrong I'm saying "Nah" and sending you back to the group. No Hints.
- 4) I will send the pastebin with the mystery program right after debriefing on the game. Once you get the link, you may start.
- PROBLEM #1: Argc and Argv
- This problem involves using argc and argv for input and output. You will take
- several strings as input FROM THE COMMAND LINE, and print them in reverse.
- Here are the steps:
- 1) Write the main function itself with parameters "int argc" and "char* argv[]".
- - This program will take a string as input AT THE COMMAND LINE when the program is started.
- - This means, in the command line, you will type "./main [word1] [word2]", and hit enter. NOT THE RUN BUTTON.
- 2) Print the words in the string in reverse order.
- - You will need to use argc and argv.
- Note: Recall that char* argv[] is an ARRAY of STRINGS. So each whole string occupies
- a single slot in the array.
- SAMPLE OUTPUT:
- > ./main here are my words [This is the command line. NOT your program output.]
- words
- my
- are }- [These 5 lines are your program's output]
- here
- ./main
- PROBLEM #2: Checking ISBN Numbers
- The International Standard Book Number, ISBN, is used to uniquely identify a book.
- It is made of 10 digits. Write a function that tests an ISBN to see if it is valid.
- For an ISBN number to be valid, the weighted sum of the 10 digits must be evenly divisible by 11.
- To determine the weighted sum, the value of each position is multiplied by its
- relative position, starting from the right, and the sum of the product is determined.
- If (weighted sum) modulus 11 is 0, the ISBN number is valid.
- Test your function with examples, use Amazon to get valid book ISBNs.
- Example
- ISBN: 0-07-881809-5 (assume no dashes in your function)
- Code * Weight = Value
- 0 10 0
- 0 9 0
- 7 8 56
- 8 7 56
- 8 6 48
- 1 5 5
- 8 4 32
- 0 3 0
- 9 2 18
- 5 1 5
- Weighted Sum is 220
- 220 % 11 = 0 (Valid ISBN)
- SAMPLE OUTPUT (ISBN is 0078818095)
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 7
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 1
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 9
- Enter in 10 numbers one at a time: 5
- Weighted Sum is: 220
- The ISBN is valid
- PROBLEM #3: Checking If a File Exists by Using it's Name
- This problem involves using File pointers! Here are the steps:
- 1) Prompt the user for the name of a text file (example: input.txt)
- - Use fscanf() to put the user input in a string.
- 2) Check if the file exists. Print the result to the user.
- SAMPLE OUTPUT (If file exists) SAMPLE OUTPUT (If file doesn't exist)
- Enter your file: file.txt Enter in your file: file.txt
- File exists File doesn't exist
- BONUS PROBLEM: Storing Strings and converting them into Float
- This problem involves taking strings as input and converting them into floating point values.
- You will use a TWO-DIMENSIONAL array to store the strings. Here are the steps:
- 1) Create a two-dimensional array of characters that can hold 10 strings up to a length of 20
- characters each. (It will be formatted as char[][], place the 10 and 20 in the proper brackets).
- 2) Declare and initalize a double called "sum" and set it to 0.
- 3) Prompt the user to enter in 10 numbers and store them into an array of chars (strings) one at a time.
- TREAT NUMERICAL INPUT AS STRINGS and store them into the array
- - You DON'T need to reference the 2nd dimension, but this part of the program is really weird, so I will give you the scanf.
- - scanf("%s", ary[i][0]);
- 4) Use a loop to print out the strings to verify that the numbers were stored in the array successfully.
- 5) Now use a second loop through the array and use the atof() function to convert the string version of the numbers into a
- double, and then add it to a sum variable.
- 6) Print out the sum and end the program.
- Note: scanf() will read in strings from standard in (stdin) until they encounter a
- space, end of file, or newline/carriage return. gets and fgets will include those items, which makes
- scanf a better choice here ( https://www.tutorialspoint.com/c_standard_library/c_function_atof.htm )
- SAMPLE OUTPUT:
- Enter in a number: 1
- Enter in a number: 2
- Enter in a number: 3
- Enter in a number: 4
- Enter in a number: 5
- Enter in a number: 6
- Enter in a number: 7
- Enter in a number: 8
- Enter in a number: 9
- Enter in a number: 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Sum: 55.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement