#include ??? // For setprecision() #include ??? // For cout, endl, fixed #includ
ID: 3762417 • Letter: #
Question
#include ??? // For setprecision()
#include ??? // For cout, endl, fixed
#include ??? // For the Color class declaration
#include ??? // For the Point class declaration
#include ??? // For the PointTest class declaration
using namespace std;
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: getInt()
//
// DESCRIPTION
// Display a prompt and read a number (as an int) from the keyboard. Return the number.
//--------------------------------------------------------------------------------------------------------------
int getInt(string pPrompt)
{
int n;
cout << pPrompt;
cin >> n;
return n;
}
//--------------------------------------------------------------------------------------------------------------
// CTOR: PointTest()
//
// DESCRIPTION
// Default constructor. Does nothing.
//
// REMARKS
// Every class must have at least one ctor, because when an object is instantiated, a ctor must be called. If
// there are no data members to initialize, then we just provide a default ctor that does nothing.
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: run()
//
// DESCRIPTION
// Tests the implementation of the Point class.
//
// PSEUDOCODE
// Define x, y, r, g, and b as int variables.
// Configure cout so real numbers are displayed in fixed notation with 3 digits after the decimal pt.
//
// Comment: Test that the default ctor works correctly.
// Define and instantiate a Point object named p1 calling the default ctor.
//
// Comment: Test that the second ctor works correctly.
// x <- getInt("Enter point p2 x? ").
// y <- getInt("Enter point p2 y? ").
// Define and instantiate a Point object named p2 passing x, y as the params to the ctor.
//
// Comment: Test that the third ctor works correctly.
// x <- getInt("Enter point p3 x? ").
// y <- getInt("Enter point p3 y? ").
// r <- getInt("Enter point p3 red? ").
// g <- getInt("Enter point p3 green? ").
// b <- getInt("Enter point p3 blue? ").
// Define and instantiate a Point object named p3 passing x, y, r, g, and b as the params to the ctor.
//
// Comment: Test that the fourth ctor works correctly.
// x <- getInt("Enter point p4 x? ").
// y <- getInt("Enter point p4 y? ").
// r <- getInt("Enter point p4 red? ").
// g <- getInt("Enter point p4 green? ").
// b <- getInt("Enter point p4 blue? ").
// Define and instantiate a Color object named color passing r, g, and b as the params to the ctor.
// Define and instantiate a Point object named p4 passing x, y, and color as the params to the ctor.
//
// Send to cout "The point p1 is " followed by p1.toString() followed by endl.
// Send to cout "The point p2 is " followed by p2.toString() followed by endl.
// Send to cout "The point p3 is " followed by p3.toString() followed by endl.
// Send to cout "The point p4 is " followed by p4.toString() followed by endl.
//--------------------------------------------------------------------------------------------------------------
???
Explanation / Answer
public class Addition 6 { 7 // Main method begins execution of C# app 8 public static void Main( string[] args ) 9 { 10 int number1; // declare first number to add 11 int number2; // declare second number to add 12 int sum; // declare sum of number1 and number2 13 14 Console.Write( "Enter first integer: " ); // prompt user 15 // read first number from user 16 number1 = Convert.ToInt32( Console.ReadLine() ); 17 18 Console.Write( "Enter second integer: " ); // prompt user 19 // read second number from user 20 number2 = Convert.ToInt32( Console.ReadLine() ); 21 22 sum = number1 + number2; // add numbers 23 24 Console.WriteLine( "Sum is {0}", sum ); // display sum 25 } // end Main 26 } // end class Addition
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.