What input parameters the function takesnbsp what results


C++ Homework

1. What are the two types of comment styles in C++?

2. Find 3 errors in the following program

// This is a little program

that calculates a modulus answer.

int main()

{

   double x,y,answer;

   answer = x%y;

   cout << "\n\n answer = << answer;

   return 0;

     }

3. What output is generated from running the following program?

#include

using namespace std;

void Red();

int main()

{

      int i = 1;

      while(i < 4)

      {

            Red();

            ++i;

      }

}

void Red()

{

      cout << "\nRed is a great color.";

}

4.  Salma wrote the following program:

#include

#include

using namespace std;

int main()

{

      float square;

      float x = static_cast(- 3.7755);

      square = x * x;

      cout << "The square of " << x;

      cout << "\nis equal to " << square << endl;

      system("pause"); // so that the screen stays up till user hints a key

      return 0;

}

Salma wants to put the underlined C++ code (above) in a separate function and wants to call it squareIt. Put the above code in a MS Visual Studio C++ project. Compile it and make sure it compiles fine and runs correctly.

What you are required to do:

Rewrite Salma's program by creating the function squareIt(). Call the function squareIt() from within the main() function. Recompile the code and make sure it compiles and runs fine and produces the same results.

When you create the function think about

1.  What the function will do

2.  what input parameters the function takes.

3.  What results it returns to the calling program.

4.  How it is called in the main.

5.  Do not forget to create a prototype for it at the top of the program.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: What input parameters the function takesnbsp what results
Reference No:- TGS01275286

Now Priced at $30 (50% Discount)

Recommended (94%)

Rated (4.6/5)