Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1: Bring in the code below into VS: // This program tests whether or not an initialized value // is equal to a value

Task 1:

Bring in the code below into VS:

// This program tests whether or not an initialized value

// is equal to a value input by the user

// PLACE YOUR NAME HERE

#include

using namespace std;

int main( )

{

int num1, // num1 is not initialized

num2 = 5; // num2 has been initialized to 5

cout << "Please enter an integer" << endl;

cin >> num1;

cout << "num1 = " << num1 << " and num2 = " << num2 << endl;

if (num1 = num2)

cout << "Hey, that's a coincidence!" << endl;

if (num1 != num2 )

cout << "The values are not the same" << endl;

return 0;

}

Exercise 1: Run the program several times using a different input each time. Does the program do what you expect? If so, explain what it is doing. If not, locate the error and fix it.

Exercise 2: Modify the program so that the user inputs both values to be tested for equality. Make sure you have a prompt for each input. Test the program with pairs of values that are the same and that are different.

Exercise 3: Modify the program so that when the numbers are the same it prints the following lines:

The values are the same.

Hey thats a coincidence!

Exercise 4: Modify the revised program from Ex 3 by replacing the two if statements with a single if/else statement. Run the program again to test the results.

Task 2:

Scientists measure an objects mass in kilograms and its weight in Newtons. If you know the amount of mass that an object has, you can calculate its weight, in Newtons, with the following formula:

Weight = mass x 9.8

Write a program that asks the user to enter an objects mass, and then calculates its weight. If the object weighs more than 1000 Newtons, display a message indicating that it is too heavy. If the object weighs less than 10 Newtons, display a message indicating that the object is too light.

Task 3:

Write code that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two data items. The first is a characterD (for diameter), C (for circumference), or A (for area)to indicate the calculation needed. The next data value is a floating-point number indicating the radius of the particular circle. The program should print the input data. The output should be labeled appropriately.

For example, if the input is: A 6.75 your program should print something like this:

The area of a circle with radius 6.75 is 143.14.

Here are the formulas you need: Diameter = 2r, Circumference = 2r, Area of a circle = r2where r is the radius. Use 3.14159265 for .

Modify your program to perform input validation by making sure that the first character is A or C or D and the value of the radius is greater than zero. An appropriate error message should be printed if invalid data was entered.

please use in C++ program I highly appreciate it a lot.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions