Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

1. Using the switch statement, write a program that will request an integer from the user in the range 1 - 5. It should then output a message in this form:

You entered the number one.
{or two, or whatever was entered}
If the user entered a number other than 1 - 5, the program should output a message to that effect. Note that you need to read the value as an int, not a char. Use the form cin >> x; where x is an int variable, not cin.get().

2. Rewrite the following code with a for loop:

int inputNum;
cin >> inputNum;
Value = inputNum;
while (Value <= 10) {
cout << Value;
++Value;
}

3. This is a two-part question.

a. Rewrite the code in the previous question using a do-while loop.

b. Under what circumstances will the do-while loop you wrote act differently than the while and for versions of this code?

4. A certain company sells three items.

Tacos: $1.67 each
Golf Bags: $158.99 each
Masking Tape Roll: $5 each
Write a program that asks the user to select one of the items from a menu (1 for tacos, 2 for golf bags, 3 for masking tape), then to enter a number to buy. The program computes the cost of the purchase, requests another item selection from the user, and so on. The user enters 0 from the item menu to quit. Once 0 has been entered, the program displays the total cost of goods purchased.

5. In a certain company, employees are paid extra for overtime using the following system. For every hour over 40 worked, the employee is paid 1.5 times hourly wages. For every hour over 50, the employee is paid 2 times hourly wages. For example, an employee who earns $10 an hour and works for 55 hours would receive:
Regular pay: 40 hrs x $10 = $400
Time-and-a-half: 10 hrs x 1.5 x $10 = $150
Double: 5 hrs x 2 x $10 = $100
Total: = $650
Write a program that prompts for the number of hours worked in a week and an hourly wage, and then calculates and displays the weekly pay.
The program should then ask the user if there is more data (have the user enter `y' for yes). If so, the process begins again with the prompt for hours worked.

6. Write a program that reads two floating-point values representing angles and displays a message stating which angle has the greater tangent value. Note that the trigonometric functions in the math library expect angles in radians, not degrees. 360 degrees = 2 x pi radians, so 45 degrees would be about 0.785 radians.

7. What is the output of the following program? Explain.
#include
using namespace std;
void f(int i, int j) {
i = 5;
j = j + i;
cout << "f: i = " << i << endl;
cout << "f: j = " << j << endl;
}
int main () {
int i = 15;
int j = 30;
f(i, j);
cout << "main: i = " << i << endl;
cout << " main: j = " << j << endl;
}

8. Write a float function GetRadius() that prompts the user for a radius, extracts the user's response from cin, and then returns the response as its value. Note: in questions of this type, you should write a simple program to test your code. All you need in this case is a main function that calls your function with appropriate arguments.

9. Create an enumerated type with three values: POSITIVE, NEGATIVE, and ZERO. Write a function that prompts the user for an integer, reads the integer, and returns one of the enumerated values based on that number (e.g., returns NEGATIVE if the input number is < 0.). Write a main function that calls this function, and displays, using a switch statement, what category of number was entered. Example:
Please enter an integer: 6
The number you entered was positive.

10. This is a two-part question.

a. Write a function for the following formula.
Distance: computes the distance d traveled in t seconds by an object that started at rest and then accelerated at a meters per second per second.
d = at^2 /2

b. Briefly discuss your choice of parameters and their types.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91607774
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As