Question

Write the c++ code that will run with visual studio With the square function below as...

Write the c++ code that will run with visual studio

With the square function below as an example, write a max function that has two int parameters and will return back the larger of the two.
Also write a main which can be used to test your function.


ex ) int square(intnum); // funcprototype
int main()
{
   inta = 5, b;
a = square(a);
   b = square(4);cout<< square( 6 ) << endl;
   ....
      
// func definition
//belown main

int square( intnum) {
       num= num* num;
       return num;
   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int square(int num); // funcprototype
int max(int n1, int n2);

int main() {
    int a = 5, b;
    a = square(a);
    b = square(4);
    cout << square(6) << endl;

    cout << "max of " << a << " and " << b << " is " << max(a, b) << endl;
    return 0;
}

// func definition
//belown main

int square(int num) {
    num = num * num;
    return num;
}

int max(int n1, int n2) {
    if (n1 > n2)
        return n1;
    else
        return n2;
}
Add a comment
Know the answer?
Add Answer to:
Write the c++ code that will run with visual studio With the square function below as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function...

    C++ 4. (5 points) Identify the following items in the programming code shown below: a. Function prototype, function heading, function body, and function definitions. b. Function call statements, formal parameters, and actual parameters. C. Value parameters and reference parameters. d. Local variables and global variables. 6. Named constants. #include <iostream> //Line 1 using namespace std; //Line 2 const double NUM = 3.5; //Line 3 int temp; //Line 4 void func(int, doubles, char); //Line 5 int main() int num; double one;...

  • Can someone help me . This program needs to run in visual studio and written in...

    Can someone help me . This program needs to run in visual studio and written in c++. I want to call to the function string eraseChar in the main function to use the variables str and ch. I cannot use global variables. #include<iostream> #include <string> using namespace std; string eraseChar(char ch = 'e', string str = "the bike fell in the water");    int main() {    int pos;    pos = str.find(ch);    while (pos != string::npos)    {...

  • C++ I am using visual studio for it. Make a copy of the Rational class you...

    C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...

  • C++ Programming Code Do not change anything in the supplied code below that will be the...

    C++ Programming Code Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include <iostream> #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList<int> list, subList; int num;                                                                                                                                    cout << "Enter...

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • Write the c++ code that run with visual studio Use for loops to display a grid....

    Write the c++ code that run with visual studio Use for loops to display a grid. −For each position, display the location’s row and column number. −Put two blanks between each location. •Example:1,1 1,2 1,3 .... 1,9 2,1 2,2 .... 2,9 .... 8,1 8,2 .... 8,9    9,1 9,2 9,3 .....9,9

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • Help please: A Modular Function: You must rewrite the code to use a modular function that...

    Help please: A Modular Function: You must rewrite the code to use a modular function that can be used again by other modules. Your main program will call the function and pass the variables by value. Your function will take the appropriate action and return the required value . (Hint you will use additional variables in your revised code). The called function must be able to accept the data passed to it by the function doing the calling. Only after...

  • 6. (Short answer) The C++ code below is very close to working, but, as written, won't...

    6. (Short answer) The C++ code below is very close to working, but, as written, won't compile. When trying to compile, the compiler generates a number of errors similar to "cout' was not declared in this scope." Respond to the prompts below about the code.(20 points, 5 points each) #include <iostream> void FindMax(int a, int b, int& max) { if (a > b) max = a; else { max = b; } int main() { int num1 = 0; int...

  • I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe...

    I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT