Question

In: Computer Science

Take the code below, add the parameter validation as prompted by the highlighted comments. #include <iostream>...

Take the code below, add the parameter validation as prompted by the highlighted comments.

#include <iostream>
using namespace std;

// Prototype (Wait, what's this? Hmmm... how would you find out? )
void calculateBill(double, int);

int main()
{
// local variables
int numMonths = 10;
double rate = 25.99;

// Perform a test for $25.99 membership.
cout << "Calling the calculateBill function with arguments "
??? << rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";

// Perform a test for 70.50 membership.
numMonths = 5;
rate = 70.50;
cout << "Calling the calculateBill function with arguments "
??? << rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";

// Perform a test for $-5 membership.
numMonths = 5;
rate = -5;
cout << "Calling the calculateBill function with arguments "
??? << rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";

//// What should you add to your function now?

// Perform a test for -10 months. Keep -5 to make sure you added that input validation
numMonths = -10;
rate = -5;
cout << "Calling the calculateBill function with arguments "
??? << rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";

//// What should you add to your function now?

return 0;
}

//*****************************************************************
// Definition of function calculateBilll. The memberRate parameter holds *
// the monthly membership rate and the months parameter holds the *
// number of months. The function displays the total charges. *
//*****************************************************************
double calculateBill(double memberRate, int months)
{
return (memberRate * months);
}

Solutions

Expert Solution

note: if you have any queries then comment below. thank you

#include <iostream>
using namespace std;

// Prototype (Wait, what's this? Hmmm... how would you find out? )
double calculateBill(double, int);

int main()
{
// local variables
int numMonths = 10;
double rate = 25.99;
double total=0;

// Perform a test for $25.99 membership.
cout << "Calling the calculateBill function with arguments "<< rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";

// Perform a test for 70.50 membership.
numMonths = 5;
rate = 70.50;
cout << "Calling the calculateBill function with arguments "<< rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";

// Perform a test for $-5 membership.
numMonths = 5;
rate = -5;
cout << "Calling the calculateBill function with arguments "<< rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";

//// What should you add to your function now?

// Perform a test for -10 months. Keep -5 to make sure you added that input validation
numMonths = -10;
rate = -5;
cout << "Calling the calculateBill function with arguments "<< rate << " and " << numMonths << "\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";

//// What should you add to your function now?

return 0;
}

//*****************************************************************
// Definition of function calculateBilll. The memberRate parameter holds *
// the monthly membership rate and the months parameter holds the *
// number of months. The function displays the total charges. *
//*****************************************************************
double calculateBill(double memberRate, int months)
{
if(memberRate<0 || months<0)
return 0;
else
return (memberRate * months);
}


Related Solutions

Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
Develop and pseudocode for the code below: #include <algorithm> #include <iostream> #include <time.h> #include "CSVparser.hpp" using...
Develop and pseudocode for the code below: #include <algorithm> #include <iostream> #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Static methods used for testing //============================================================================ /** * Display the bid information...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip>...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<algorithm> using namespace std; const int row = 10; const int col = 7;   ifstream name; ifstream grade; ofstream out; void readData(string stname[row], int stgrade[row][col]); void stsum(int stgrade[row][col], int total[row]); void staverage(int total[row], double average[row]); void stlettergrade(double average[row],char ltrgrade[row]); void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]); void swapltrgrade(char* xp, char* yp); int main() {    int STG[row][col] = { {0},{0}...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std;...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std; int main() { enum AcceptedCoins {ADD_QUARTER, ADD_DIME, ADD_NICKEL, ADD_UNKNOWN}; AcceptedCoins amountDeposited = ADD_UNKNOWN; int totalDeposit = 0; int usrInput = 0; cout << "Add coin: 0 (add 25), 1 (add 10), 2 (add 5). "; cin >> usrInput; if (usrInput == ADD_QUARTER) { totalDeposit = totalDeposit + 25; } /* Your solution goes here */ else { cout << "Invalid coin selection." << endl;...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib>...
fix the code with constant expression error exrpession below in visual studio #include <iostream> #include <cstdlib> #include <ctime> void insertion_sort(int array[], int size, int start); void heap_sort(int B[], int n); void build_max_heap(int B[], int n); void max_heapify(int B[], int i, int n); void quick_sort(int B[], int p, int r); int partition(int B[], int p, int r); int main() {    int m = 10, Nf = 20000, Ns = 1000, delta = 1000, A[m][Nf];    for (int i = 0;...
Your task is to take the below code, and insert comments (using the “%” symbol) next...
Your task is to take the below code, and insert comments (using the “%” symbol) next to each line of code to make sure that you know what every line does. clc clear close all NMax = 100; partialSum = 0; exactAnswer = pi^2; for k=1:NMax partialSum = partialSum + 6/k^2; percentDiff(k) = abs(partialSum - exactAnswer)/exactAnswer*100; end NVector = [1:NMax]; plot(NVector,percentDiff); xlabel('{{Noob}}'); ylabel('% Difference');
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom66(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
Please explain this C++ below on how to get the following outputs (see code) #include <iostream>...
Please explain this C++ below on how to get the following outputs (see code) #include <iostream> using namespace std; // Tests for algorithm correctness // ------------------------------- // 1 gives output "1 3   7 15 31 63 127 255 511 1023 2047" // 2 gives output "2 5 11 23 47 95 191 383 767 1535 3071" // 3 gives output "3 7 15 31 63 127 255 511 1023 2047 4095" // 5 gives output "5 11 23 47 95...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT