Purchase Solution

Various small C++ programming problems

Not what you're looking for?

Ask Custom Question

6. Consider the following sequence of C++ code

int age;
cout << "Please enter your age: "<<endl;
cin>> Age;

Would this code sequence compile? Explain. (5 points)
Answer:

17. What does the following pseudocode do? (4 points)

Input x
Input y
Set result = (x+y)/2
Output result
Answer:

18. Using pseudocode or C++, write the statements to enter an integer number, compute the number raised to power 5 and output the result. (11 points)
Answer:

19. Using pseudocode or C++, write the statements to enter two integer numbers, switch their values and output the result. (11 points)
Answer:

20. Using pseudocode or C++, write the statements to enter an integer number, determine if it is even or odd and print "The number is even" if it is even or "The number is odd" if it is odd (11 points)
(Hint: the % operator returns the remainder of the division of a number by another. For example 5%2 returns 1 because the remainder of 5 divided by 2 is 1).
Answer:

Purchase this Solution

Solution Summary

This solution shows several small C++ programming problems. The focus is on simple arithmetic programs.

Solution Preview

I have provided help and explanation for each of the questions you asked below. I've provided pseudocode in most cases since that might be easier for understanding the concepts.

----
6. Consider the following sequence of C++ code

int age;
cout << "Please enter your age: "<
cin>> Age;

Would this code sequence compile? Explain. (5 points)
Answer:
----

This sequence would not compile. There are a couple of problems. First of all, the second statement has a trailing "<" that will cause a syntax error. That symbol should be a ;. All statements in C++ need to end in a ";" character.

Second, the third line is using a unknown variable. "Age" is not declared but "age" is. Notice that the first line of the sample code has "int age;". That declares a new integer variable named "age". Since C++ is case sensitive "age" is not the same as "Age". The first or third lines need to be edited to match each other.

----
17. What does the following pseudocode do? (4 points)

Input x
Input y
Set result = (x+y)/2
Output result
Answer:
----

This bit of pseudocode reads in two ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

C++ Operators

This quiz tests a student's knowledge about C++ operators.