CIS 150 Lab 4: Functions, input validation – With C++ Code – Perfect Solution – Instant Delivery

Lab Price = $10
Please feel free to send us your queries at: support@iqrajavaid.com
Payment methods

Add to Cart

Buy Now

View Cart


Problem Statement

Objectives
• Write user-defined functions
• Use user-defined functions
• Validate user input
Requirements
Modify the supplied program (functionLab.cpp) to make it work properly.
/*
functionLab.cpp
Name:
CIS 150
Date:

CIS 150 Chapter 6 Function Lab
*/

/*
Place your name and section at the top in comments.
Read the instructions for each section and then implement
your solution within this program.

You can comment out sections as you work. Declare variables
if necessary. You do not need to get input from the user
unless otherwise specified or that code is already written.

For this lab you will use the code in the file and
break it into functions. Code for functions has been marked
for you. To do this you will:

1. Cut the code from main() and paste
it below the closing } for main.

2. Declare the local variables in the function.

3. Create the prototypes for the function.

4. In main(), determine which variable declarations need to remain there
and which variables should be isolated to the various functions.

5. Call the functions, passing values as needed and using assignment
statements for any values returned from the functions.

6. Run and debug your program.

7. When the program is running correctly, upload the completed file to
D2L.
*/

#include
#include
#include
using namespace std;

/*******************************Prototypes******************************/

/*******************************main line*******************************/
int main() {
double x, miles, gallons, mpg, time;
bool valid;

/* The following while loop should become a function to get
and validate input from the user. The function should take three
parameters: a prompt, a minimum value, and a maximum value. The
minimum and maximum values in the loop below are the values 1 and
600. Use the function to get a value for miles. */
valid = false;
while (!valid) {
cout << "Enter the miles driven (1-600): "; if (cin >> x) {
if (x < 1) { cout << "Error: The minimum value is 1\n"; } else if (x > 600) {
cout << "Error: The maximum value is 600\n"; } else { valid = true; } } else { cin.clear(); cin.ignore(500, '\n'); cout << "Error: Invalid number\n"; } } miles = x; /* Reuse the function you created for the previous input validation to get the value for gallons. The same function should work for both. */ valid = false; while (!valid) { cout << "Enter the gallons used (1-50): "; if (cin >> x) {
if (x < 1) { cout << "Error: The minimum value is 1\n"; } else if (x > 50) {
cout << "Error: The maximum value is 50\n"; } else { valid = true; } } else { cin.clear(); cin.ignore(500, '\n'); cout << "Error: Invalid number\n"; } } gallons = x; /* The following should become one function to calculate the mpg. The function should take miles and gallons as input and return the mpg. */ mpg = miles / gallons; /* The following should become one function to calculate the time (in hours) to drive the given miles going 60 miles per hour. The function should take miles and return miles / 60. */ time = miles / 60; /* The following should become one function to display the mileage information to the user. The function should take miles, gallons, mpg, and time as input. */ cout << "Your mileage specs are\n"; cout << fixed << showpoint << setprecision(2) << "Miles: " << setw(6) << miles << '\n' << "Gallons: " << setw(6) << gallons << '\n' << "MPG: " << setw(6) << mpg << '\n' << "Time: " << setw(6) << time << '\n'; /* Hold the screen open */ /* You can delete the next three lines if using Quincy */ cout << "Press enter to continue..."; cin.ignore(); cin.get(); return 0; } Example run of program Enter the miles driven (1-600): -2 Error: The minimum value is 1 Enter the miles driven (1-600): 650 Error: The maximum value is 600 Enter the miles driven (1-600): 345 Enter the gallons used (1-50): 14.5 Your mileage specs are Miles: 345.00 Gallons: 14.50 MPG: 23.79 Time: 5.75 Press enter to continue... Rubric • 4 points: for getting the function that gets a double working properly and using it • 2 points: for getting the function that calculates the mpg working properly and using it • 2 points: for getting the function that calculates the mph working properly and using it • 2 points: for getting the function that displays the results working properly and using it

Relevant Material
Screenshots

Lab 4: Screenshot
Lab 4: Screenshot
Instructions
* If you want to purchase multiple products then click on “Buy Now” button which will give you ADD TO CART option.Please note that the payment is done through PayPal.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at support@iqrajavaid.com.
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at support@iqrajavaid.com and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at support@iqrajavaid.com.
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Privacy Policy
We take your privacy seriously and will take all measures to protect your personal information.
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
Refund Policy
Incase you face any issues with the tutorial, please free to contact us on support@iqrajavaid.com
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.
Payment Details
Lab Price = $10
Please feel free to send us your queries at: support@iqrajavaid.com

Payment methods

Add to Cart

Buy Now

View Cart

Leave a Reply