Question

In: Computer Science

Language C++ *note* Your function count should match those given in the description; you have no...

Language C++

*note* Your function count should match those given in the description; you have no need for extra functions beyond that, and you should not have less.

-Write a function, doTheRegression(), that takes as input a variable of type integer and returns a value of type double. It computes and returns 80% of the value given as the amount after reduction.

-In your main function, write code that asks the user what the original amount is, and if they are splitting profits this week. You may assume that the user always enters reasonable input ("yes" and "no" is enough).

-Input should be done one question at a time.

-If the user answers "no", call function doTheRegression() on the original value to get an appropriate answer.

-If the user answers "yes", ask the user for the number of people splitting the profits.

-If the user answers "yes", call an overloaded version of function doTheRegression() that takes two inputs of type integer; this function takes the exact division of the original amount and the number of people splitting profits, and then returns 90% of the value given.

-Your code should run at least 2 times, so that it can properly be tested.

-Output should be accurate to 1 decimal place.

-Use pre existing functions as necessary to make sure that all excess input is being discarded, every time the user finishes inputting input.

Sample Output:

Original amount: 24

Are you splitting profits? no

Reduced value: 19.2

Original amount: 26

Are you splitting profits? Yes

How many people? 3

Reduced value: 7.8

*Explanation* 80% of 24 is 19.2, the first case should be calling the original function. 26/3 is 8.6 repeating, and 90% of that leaves 7.8; the second case should be calling the overloaded function.

Solutions

Expert Solution

Code

#include<iostream>
using namespace std;

double doTheRegression(int x)
{
    double v =(double) (x*80)/100;
    return v;
}
double doTheRegression (int x,int y)
{
    double v= (double) x/3;
    v= (v*90)/100;
    return v;
}
int main()
{
    cout<<"Enter original amount :";
    int x; //input the original amount
    cin>>x;
    cout<<"are you splitting profits? ";
    string s;
    cin>>s; //input splitting or not
    if(s=="yes") //if yes call the overloaded function
    {
        cout<<"how many people? ";
        int p;
        cin>>p;
        double d= doTheRegression (x,p);
        cout<<"Reduced value: "<<d;
    }
    else //if no call the doTheRegression
    {
        double d=doTheRegression (x);
        cout<<"Reduced value: "<<d;
    }
    return 0;
}

Terminal Work

.


Related Solutions

TO BE DONE IN C LANGUAGE BEFORE READING THE QUESTION PLEASE NOTE THAT YOUR FUNCTION SHOULD...
TO BE DONE IN C LANGUAGE BEFORE READING THE QUESTION PLEASE NOTE THAT YOUR FUNCTION SHOULD EXACTLY PRODUCE THE GIVEN OUTPUT AND THE TIME COMPLEXITY SHOULD BE O(N^2) YOU NEED TO KNOW ABOUT COCKTAIL SHAKER SORT ALGORITHM: Cocktail-shaker sort is a modification of Bubble sort. Cocktail-shaker sort traverses the data structure in one direction, pushing the largest element ahead towards one end of the data structure, and then in the opposite direction, pushing the smallest element towards the other end,...
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...
Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART A: (Minusculo Inn) Minusculo Inn has only eight guest rooms: Room Number Amenities 101 1 king size bed 102, 103,104 2 double beds 201, 202 1 queen size bed 203, 204 1 double bed & sofa bed Write a program that asks for the room number and displays the amenities. If the user enters a room number that does...
Class object in C++ programming language description about lesson unary overloading function example.
Class object in C++ programming language description about lesson unary overloading function example.
Note: I need a code and other requirement Note: programming language is c++ If you need...
Note: I need a code and other requirement Note: programming language is c++ If you need more information, please clarify what information you want. consider solving the equation sin(x) - e^(-x) = 0 write a computer program to solve the given equation using: 1- bisection method 2- fixed-point method 3- newton's intervals: {0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10} choose accuracy E = 10^(-5) Make sure you document your program Requirement : 1- Mathematical justification 2- algorithem description 3- code (program) with documentation 4-output: roots ,...
C LANGUAGE ONLY Write a C program to count the frequency of each element in an...
C LANGUAGE ONLY Write a C program to count the frequency of each element in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements of the array: element [0]: 25 element [1]: 12 element [2]: 43 Expected output: The frequency of all elements of an array: 25 occurs 1 times 12 occurs 1 times 3 occurs 1 times
on C++ language please and if you can also put note on it to better undertand...
on C++ language please and if you can also put note on it to better undertand it. Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements: Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file. Save the output of...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements in the arrangement: element [0]: 5 element [1]: 1 element [2]: 1 Expected output: The total number of duplicate elements found in the array is: 1
Use C language Problem 1: Buy cheese (Level 1) • Problem description You have M dollors...
Use C language Problem 1: Buy cheese (Level 1) • Problem description You have M dollors and want to buy as much cheese as possible. There is a cheese shop with two kinds of cheese. The unit prices of the both cheese are p1 and p2, the total amount of them are a1 and a2. You can buy either cheese or both, but the amount you buy cannot exceed its total amount. Write a program to output the largest amount...
in C programming language Write a function removeDups that removes all duplicates in a given array...
in C programming language Write a function removeDups that removes all duplicates in a given array of type int. Sample Test Case: input -> {1,2,2,2,3,3,4,2,4,5,6,6} output -> {1,2,3,4,5,6,0,0,0,0,0,0} More specifically, the algorithm should only keep the first occurance of each element in the array, in the order they appear. In order to keep the array at the same length, we will replace the removed elements with zeros, and move them to the end of the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT