Lab-3
Functions and Parameters
Pre-lab reading materials
Until Chapter 5 on Zyante, especially 5.5, 5.6,5.7 and 5.8.
Announcements
We will have a simple 1 minutes’ quiz at the beginning of the lab on Blackboard. Please sign in to your Blackboard account and finish the quiz individually. Most of your time should be focused on finishing the lab activity questions. To access the quiz, go to CS 141 course on Blackboard, and click on Quiz, there you can find quiz 3. To access the quiz, you will need a password, which will be announced by the TA in the lab.
The full version of lab assignment is on CS141 course page, under the link "Lab,TA, Tutoring" > "Lab 3 ".
You must work with a single partner, in a group of 2. You must take turns being the “driver” and the “navigator”. (If there are an odd-number of students in the class, your TA will make an adjustment.)
Lab Grading policy
There are 3 question. The maximum score is 2, where each question is worth 1 point. Question 3 is extra credit. To get a grade, you must show your work to TA before your lab session ends. NO submission needed. Once you finish your work, please raise your hand and show your work to your TA during the last 10 minutes of lab. Please leave the lab when the lab session ends, since we need to spare room for the next section.
Lab Activity
During the lab section today, you need to implement three individual functions for a program, with progressing complexities. We will also supply a sample function for you.
Steps You Need to Do
(1 piont)Transfer of control:
function to display name and movie you would like to see
(1 point)Return value:
function that prompts for number of people going and then print that value * 8 is the total price. This should be caught in a variable in main, and then printed out.
(extra credit, 1 point) Return value plus value parameters:
Send the total price and any discount value to a function, which returns the price - discount. This should be caught in a variable in main, and then printed out.
Running the program should look like:
Lab 3: Movie Tickets
Name: Englebert Humperdink, Movie: Sing
How many people are going? 2
Total price is: 16
Enter discount value: 1
Total price including discount is: 15
Running the program a second time might look like:
Lab 3: Movie Tickets
Name: Fred A. Stair, Movie: Singing in the Rain
How many people are going? 3
Total price is: 24
Enter discount value: 5
Total price including discount is: 19
Sample Code
#include <stdio.h>
// 1. Write the displayNameAndMovie() function here
// ...
// 2. Write the promptForHowManyPeopleGoing() function here
// ...
// 3. Write the computeDiscount() function here
// ...
int main()
{
int peopleGoing = 0;
int discountValue = 0;
int totalWithDiscount = 0;
printf("Lab 3: Movie Tickets \n");
displayNameAndMovie();
peopleGoing = promptForHowManyPeopleGoing();
printf("%d", peopleGoing);
printf("Total price is: %d \n", peopleGoing * 8);
printf("Enter discount value: ");
scanf("%d", &discountValue);
totalWithDiscount = computeDiscount( peopleGoing * 8, discountValue);
printf("Total price including discount is: %d \n", totalWithDiscount);
return 0;
}
1-24-2017