menu
bartleby
search
close search
Hit Return to see all results

Based on the code that I already have, please help me complete it. I am attempting to use 2 functions with a created menu. Pls do not use another method of fixing my code but go with the code already given, my current code is giving error display for the switch statement. Proper parameters for the functions in the switch statement need to be adjusted. And the second function in the switch statement also has overloaded that need to get fixed.This code is something that Im working on my own, non related to school work. It is part of a book that I bought to continue practicing my coding skills through the summer so pls follow my requests, thank you#include <iostream>#include <string>#include <iomanip>using namespace std;template <class T> T absolute(T val){ if (val < 0) return val * (-1); return val; }void integer_call(int &x1, int &x2, int &x1_holding, int &x2_holding);void double_call(double &y1, double &y2, double &y1_holding, double &y2_holding);int main(){cout << fixed << showpoint << setprecision(2);do{cout << "-------------------------------------------------\n";cout << "\tAbsolute Value Template" << endl;cout << "1) To test integers press 1." << endl;cout << "2) To test doubles press 2." << endl;cout << "0) To Quit" << endl;char option[20]; cin >> option;switch (atoi(option)){case 1: integer_call(); break;case 2: double_call(); break;default: exit(0);}}while (true);cout << endl;system("pause");return 0; void integer_call(int &x1, int &x2, int &x1_holding, int &x2_holding){cout << "Please enter the 1st number as an integer: ";cin >> x1;cout << "Please enter the 2nd number as an integer: ";cin >> x2;x1_holding = absolute(x1);cout << "\nAbsolute value of 1st number " << x1 << " is: " << x1_holding << endl;x2_holding = absolute(x2);cout << "Absolute value of 2nd number " << x2 << " is: " << x2_holding << endl;}void double_call(double &y1, double &y2, double y1_holding, double y2_holding){cout << "Please enter the 1st number as a double: ";cin >> y1;cout << "Please enter the 2nd number as a double: ";cin >> y2;y1_holding = absolute(y1);cout << "\nAbsolute value of 1st number " << y1 << " is: " << y1_holding << endl;y2_holding = absolute(y2);cout << "\nAbsolute value of 2nd number " << y2 << " is: " << y2_holding << endl;}

Question

Based on the code that I already have, please help me complete it. I am attempting to use 2 functions with a created menu. Pls do not use another method of fixing my code but go with the code already given, my current code is giving error display for the switch statement. Proper parameters for the functions in the switch statement need to be adjusted. And the second function in the switch statement also has overloaded that need to get fixed.

This code is something that Im working on my own, non related to school work. It is part of a book that I bought to continue practicing my coding skills through the summer so pls follow my requests, thank you

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

template <class T> T absolute(T val)

{ if (val < 0) return val * (-1); return val; }

void integer_call(int &x1, int &x2, int &x1_holding, int &x2_holding);

void double_call(double &y1, double &y2, double &y1_holding, double &y2_holding);

int main()

{

cout << fixed << showpoint << setprecision(2);

do

{

cout << "-------------------------------------------------\n";

cout << "\tAbsolute Value Template" << endl;

cout << "1) To test integers press 1." << endl;

cout << "2) To test doubles press 2." << endl;

cout << "0) To Quit" << endl;

char option[20]; cin >> option;

switch (atoi(option))

{

case 1: integer_call(); break;

case 2: double_call(); break;

default: exit(0);

}

}

while (true);

cout << endl;

system("pause");

return 0; 

void integer_call(int &x1, int &x2, int &x1_holding, int &x2_holding)

{

cout << "Please enter the 1st number as an integer: ";

cin >> x1;

cout << "Please enter the 2nd number as an integer: ";

cin >> x2;

x1_holding = absolute(x1);

cout << "\nAbsolute value of 1st number " << x1 << " is: " << x1_holding << endl;

x2_holding = absolute(x2);

cout << "Absolute value of 2nd number " << x2 << " is: " << x2_holding << endl;

}

void double_call(double &y1, double &y2, double y1_holding, double y2_holding)

{

cout << "Please enter the 1st number as a double: ";

cin >> y1;

cout << "Please enter the 2nd number as a double: ";

cin >> y2;

y1_holding = absolute(y1);

cout << "\nAbsolute value of 1st number " << y1 << " is: " << y1_holding << endl;

y2_holding = absolute(y2);

cout << "\nAbsolute value of 2nd number " << y2 << " is: " << y2_holding << endl;

}

 

 

 

check_circleAnswer
Step 1

Corrections in Program:

  • Add a closing bracket after return statement of main.
  • Remove the parameters from functions as they are not needed.
  • Since nothing is passed onto the function and there is no need to, remove the parameters from the functions’ definition and declarations and add local variables to both the functions.
  • Address of parameters is passed (like in the given code) when either the value of integer 1 and 2 were taken in main or those parameters are accessed in main. Since none of those is happening, there is no need to add parameters.
Step 2

Correct Program:

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

template <class T> T absolute(T val){ if (val < 0) return val * (-1); return val; }

// remove paratemeters as they are not needed

void integer_call();

void double_call();

 

int main(){

     cout << fixed << showpoint << setprecision(2);

     do

     {

          cout << "-------------------------------------------------\n";

          cout << "\tAbsolute Value Template" << endl;

          cout << "1) To test integers press 1." << endl;

          cout << "2) To test doubles press 2." << endl;

          cout << "0) To Quit" << endl;

          char option[20]; cin >> option;

          switch (atoi(option))

          {

              case 1: integer_call(); break;

              case 2: double_call(); break;

              default: exit(0);

          }

     }

     while (true);

     cout << endl;

     system("pause");

     return 0;

    

} // add a closing bracket

 

// remove paratemeters as they are not...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Consider a 32-bit hexadecimal number stored in memory as follows: Address Value 100 2A 101...

A: Answer:In Little Endian the order is reversed. So the binary representation of reversed order is as ...

question_answer

Q: Nine coins are placed in a 3x3 matrix with some face up and some face down. You can represent the st...

A: As there is no programming language mentioned, we are writing this program in JAVA. The program is g...

question_answer

Q: Find regular grammars for the following languages on {a, b}: L = {w : na (w) and nb (w) are both eve...

A: Regular grammar for the language L = {W: na (w) and nb (w) are both even} is as follows:

question_answer

Q: Consider the following two assertions. Assume x is a specific but unknown real number.a. x &lt; 2 o...

A: Let us name the statements as following:For expression (a)A: x &lt; 2B: Not(1 &lt; x &lt; 3)so the e...

question_answer

Q: Eliminate all unit-productions from the grammar in S → a |aA| B|C, A → aB|λ, B → Aa, C → cCD, D → dd...

A: Let us start to define unit production and how can we remove unit productions.Unit production:- A un...

question_answer

Q: This table is in 1NF. What does the table look like in 3NF? This is about Normalization.

A: First to make the table clears 3NF we need to understand what is Normal form.* Basically normal form...

question_answer

Q: health informatics

A:  I think the student wants to know what health informatics is, so we will be providing a brief intro...

question_answer

Q: Find an nfa that accepts the complement from L (ab∗aa + bba∗ab)?

A: Solution:The following graph indicates the NFA (Non-deterministic finite automata) is given below:M ...

question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz =2; y = z + x;...

A: Call by reference The arguments passed to a function will copy the address of an argument into the f...

Sorry about that. What wasn’t helpful?