+1(978)310-4246 credencewriters@gmail.com
  

Description42
468
335
501
170
725
479
359
963
465
706
146
282
828
962
492
996
943
828
437
392
605
903
154
293
383
422
717
719
896
448
727
772
539
870
913
668
300
36
895
704
812
323
334
674
665
142
712
254
869
548
645
663
758
38
860
724
742
530
779
317
36
191
843
289
107
41
943
265
649
447
806
891
730
371
351
7
102
394
549
630
624
85
955
757
841
967
377
932
309
945
440
627
324
538
539
119
83
930
542
834
116
640
659
705
931
978
307
674
387
22
746
925
73
271
830
778
574
98
513
987
291
162
637
356
768
656
575
32
53
351
151
942
725
967
431
108
192
8
338
458
288
754
384
946
910
210
759
222
589
423
947
507
31
414
169
901
592
763
656
411
360
625
538
549
484
596
42
603
351
292
837
375
21
597
22
349
200
669
485
282
735
54
1000
419
939
901
789
128
468
729
894
649
484
808
422
311
618
814
515
CS-181 Lab 6
Student Learning Outcomes





More experience coding loops
More experience coding decision structures
Data validation
Coding user-defined functions
Function overloading
Overview
This lab provides a hands-on opportunity to apply some of the terminology and concepts presented in chapter 6. As you saw in
chapter 6, user defined functions are a great way to break a complex program into “more workable pieces” and you might be
able to reuse some of the functions you code in this lab for other programming projects somewhere down the road. Code reuse
is the other powerful feature of functions.
For all exercises, be sure to copy, paste, and fill out the program comment header at the top of each file.
For each user defined function, place a function comment header above each function and fill out.
Exercise 1: Area of a Rectangle
Write a program that asks the user to enter the length and width of a rectangle. It should then calculate the area and then display
the length, width and area of the rectangle.
Your program must contain the following functions:
A function called getLength() that will prompt the user for a length and return the length. Input value must be >= 1
A function called getWidth() that will prompt the user for a width and return the width. Input value must be >= 1
A function called calcArea() that will accept length and width as arguments and return the area. Area = Length * Width
A function called displayInfo() that will accept length, width and area as arguments and display length, area and width. Sample
output provided below.
Major point deductions if any/all the user defined functions are missing!
Your program output should look something like this:
Try to use simple values for testing so you can readily tell if your calculations are coming out correct.
1
Exercise 2: Falling Distance
When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a
specific time period:
The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the
object has been falling.
Write a function named fallingDistance that accepts an object’s falling time (in seconds) as an argument. The function should
return the distance, in meters, that the object has fallen during that time interval.
Write a program that demonstrates the function by calling it in a loop that passes the values 1 through 10 as arguments and
displays the return value.
Your program output should look something like this:
2
Exercise 3: Coin Flip Simulation
Write a function named coinFlip that simulates flipping a coin. When you call the function, it should generate a random number in
the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function
should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed, then
simulates the tossing of the coin that number of times.
Maintain a count of heads and tails and display the total number of heads and tails at the end of the program.
Hint: Review pages 128 – 131 in the text for some good sample random number generator code.
Your program output should look something like this:
3
Exercise 4: Hospital Charges (Function Overloading)
Write a program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient
was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered:

The number of days spent in the hospital

The daily rate

Hospital medication charges

Charges for hospital services (lab tests, etc.)
The program should ask for the following data if the patient was an outpatient:

Charges for hospital services (lab tests, etc.)

Hospital medication charges
The program must use two overloaded functions to calculate the total charges. One of the functions must accept arguments for
the inpatient data, while the other function accepts arguments for outpatient information. Both functions should return the total
charges.
Input Validation: Do not accept negative numbers for any data.
Your program output should look something like the sample screen shots below. Be sure to test both in-patient and out-patient.
Choose simple values so you can readily tell if the charges are calculating correctly.
In-patient sample output:
Out-patient sample:
4
Assignment Submission
Your completed assignment must be uploaded to Canvas in a zip file format. Be sure you have folders for all 4 exercises in your
Lab06 folder and you have all files and sub-folders needed to open with Visual Studio.
Grading Criteria:
5
Deliverable
Points
Breakdown
Exercise 1
12
Exercise 2
12
Exercise 3
12
Exercise 4
14
Opens in VS, code is clear (I.e., appropriate variable
names, use of constants, comments, program header),
compiles, runs, produces correct output. Output formatted
correctly
Opens in VS, code is clear (I.e., appropriate variable
names, use of constants, comments, program header),
compiles, runs, produces correct output. Output formatted
correctly
Opens in VS, code is clear (I.e., appropriate variable
names, use of constants, comments, program header),
compiles, runs, produces correct output. Output formatted
correctly
Opens in VS, code is clear (I.e., appropriate variable
names, use of constants, comments, program header),
compiles, runs, produces correct output. Output formatted
correctly
Lab Total
50
/**********************************************************************
Function name: Function name here
Purpose: Brief description of its purpose
Inputs: Describe any parameters passed in
Returns: What does this function return? You can use
“None”, “Nothing” or “Void” if nothing gets returned
Revision history
Date By Description
————————————————————————
mm/dd/yyyy Name Created
mm/dd/yyyy Name Describe revisions, bug fixes, etc.
************************************************************************//*************************************************************************
Cuyamaca College CS-181
File name: fileName.cpp
Description: Lab #, Exercise #, Brief description of exercise
Developer: Your name here!
*************************************************************************/
Purchase answer to see full
attachment

  
error: Content is protected !!