Question

1. int numDash=(5 + 8) / 2; for (i=0; i<numDash; i++)    cout<<"-"; How many dashes...

1. int numDash=(5 + 8) / 2;

for (i=0; i<numDash; i++)

   cout<<"-";

How many dashes will be printed out from the above code?

2. Calculate a test average in a variable named avg and then print it out. The variable avg when printed should have two numbers to the right of the decimal point. (example - 98.56)

The average is calculated by using integer division. Divide an integer variable named earned by an integer variable named max, and then multiply 100. Assume that all of the variables (avg, earned, and max) have been properly declared. (Your answer should be two statements of code).

3. Write the C++ code to get a radius (r) from the user and calculates the area of a circle in a variable called area. You may assume a symbolic constant called PI has been defined. You do not have to print the area, just calculate it after receiving the radius from the user.

The formula is:

Area = Πr2    <-- this formula is (PI * r squared )

Homework Answers

Answer #1

Greetings!!!!!

Please find the answers as below.

1. 6 dashes will be printed by given code; Because 8+5 is computed first which gives 13. 13/2 will give 6 in integer form, as result of operation between two integers will be an integer. So value of numDash variable will be computed as 6. For loop will run for value of i=0 to i < 6 (which is 6 times as for values of i=0,1,2,3,4,5 ) print statement will be executed. Screen shot of sample run is as below.

2) Two statement code for the question number 2 is as below. It will never produce output of avg as float value. because we are performing entire calculation ((earned/max)*100) among integers, which will finally return an integer value.Two statement code for the question number 2 is as below.

avg=(earned/max)*100;
cout<<avg;

Screen shot of the above explanation is with sample run is as below.

3) C++ code for the third question is as below.

#include<iostream>
#define PI 3.14159

int main()
{
   double area,r;
   
   cout<<"Enter radius (r): ";
   cin>>r;
   area= PI*r*r;
   
}

Sample run screen shot of the above code is as follows.

Thank You

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item = 0; 4. while (count < 4) { 5.      cout << "Enter item cost: "; 6.      cin >> item; 7.      item_total += item; 8.      ++count; 9. } 10. int average_cost = round(item_total / count); 11. cout << "Total cost: " << item_total << "\nAverage cost: " << average_cost; (Refer to Code Example 8-1.) If the user enters 5, 10, and 15 at the prompts, the output is: Total...
In C programming, Thank you Write a program to compute the area of a circle. You...
In C programming, Thank you Write a program to compute the area of a circle. You have to write a complete “C” program that compiles and runs in Codeblocks. Program requirements: 1. Declare the variables needed: radius (r) and area (yourLastName). 2. Calculate and print the area of each circle. 3. The program MUST prompt the user for a new radius (r) over and over until the user types -1. 5. Use the type double for all decimal numbers. 6....
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
In this assignment, you’ll make an inventory system for a store’s items, including produce and books....
In this assignment, you’ll make an inventory system for a store’s items, including produce and books. The starter program is an inventory system for only produce. 1. Include the price of an item by adding to the Item class the protected data member int priceInDollars that stores the price in dollars of an individual item. Write a public function SetPrice with a single int parameter prcInDllrs and returns nothing. SetPrice assigns the value of prcInDllrs to priceInDollars. Modify the AddItemToInventory...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
1)         Prove (with an ε- δ proof) limx→22x3-x2-3x=6 2)         fx= x5-5x3       a)   Find the first derivative....
1)         Prove (with an ε- δ proof) limx→22x3-x2-3x=6 2)         fx= x5-5x3       a)   Find the first derivative. b)   Find all critical numbers. c)   Make a single line graph showing where the function is increasing and where it is decreasing. d) Find the coordinates of all stationary points, maxima, and minima. e)   Find the second derivative. Find any numbers where the concavity of the function may change. f) Make a single line graph showing the concavity of the function. Find the coordinates...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT