Question

In: Computer Science

Please answer urgently its 3 questions 1. If a=20 and b=10, and the types of a...

Please answer urgently its 3 questions

1. If a=20 and b=10, and the types of a and b are int, then what will be the result of a%b?

(b). Suppose x is of type double. Fill in the dotted blank below to print x correct to one decimal place: cout << ............................... ;

2. Fill in the two dotted blank spaces below such that the output of the code will be: 35. int a ........... 7;

a ........... 7 ? cout<<5*a : cout<<4*a;

3. Indicate if each of the following will be represented accurately by a variable of type double by saying ”yes” or ”no” for each: (i) 1.0; (ii) 1/2; (iii) 1/3; (iv) 1/10.

Solutions

Expert Solution

Ques 1)

a) a%b will print 0. '%' is the modulus which prints the remainder when a is divided by b.

When 20 is divided by 10 the remainder is zero, hence the output is 0.

b) cout<<setprecision(2)<<x;

The function 'setprecision()' is a predefined function in the 'iomanip' header file. It is used to set the precision of decimal numbers up to the required number of decimal places.

Ques 2)

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
        int a = 7;
        a == 7? cout<<a*5 : cout<<a*4;
}

In the first blank '=' operator is used to assign a value of a to 7.

In the second blank '==' operator is used to check if the value of a is equal to 7.

'=' is used because 35 is a factor of 5 and 7, so the value of a is assigned as 7.

'==' is used because 7*5 = 35, so to make the condition true, the equal operator is used.

Ques 3)

i) No. By default in C++, if the value after decimal place is zero, then double truncates zeros, so this will be printed as '1'.

ii)No

iii)No

iv) No

The reason for the above is if we directly assign a double variable the value like 1/3 or 1/10, etc. Then it performs integer division which results as 0.

Hence, if we assign double x = 1/3, it will give output as 0.

So none of this number will be printed accurately.

Note:- Please comment down if you face any problem. :)


Related Solutions

Explain Fisher’s Quantity Theory of Money. What are its criticisms? please answer urgently
Explain Fisher’s Quantity Theory of Money. What are its criticisms? please answer urgently
Please answer the following questions of the genus Salmonella, 1) Describe its A) colony morphology B)...
Please answer the following questions of the genus Salmonella, 1) Describe its A) colony morphology B) cell arrangement answer would be: 1) (chains, which includes Diplococcus and/OR Chain of cocci) 2) (Packets) or 3) (Clusters) 2) Information on the different places it can be found (microbiota, environmental, plant symbioses, water systems). 3) EMB is used to Identify fecal coliforms capable of lactose and/or sucrose fermentation what would the results be for Salmonella a) Growth is Pink. Organism ferments lactose with...
3) Please answer questions A and B based on the following information: The director of transportation...
3) Please answer questions A and B based on the following information: The director of transportation of a large company is interested in the usage of her van pool. She considers her routes to be divided into local and non-local. She is particularly interested in learning if there is a difference in the proportion of males and females who use the local routes. She takes a sample of a day's riders and finds the following: Male Female Local 35 36...
Please answer questions 1 - 5. Thank you. 1. What are the three types of financial...
Please answer questions 1 - 5. Thank you. 1. What are the three types of financial assets? Please give one example or each asset category. 2. What is the difference between commercial papers and treasury bills? 3. List five money market instruments. 4. What are the benefits that are unique to municipal bonds? 5. What are the differences between common stock and preferred stock?
Please answer all the following questions in depth. 1. Describe the four types of Not-for-Profit entities....
Please answer all the following questions in depth. 1. Describe the four types of Not-for-Profit entities. 2. Discuss the role of funds in accounting for NFP’s. 3. Discuss donor imposed restrictions on the use of contributions. 4. Describe the 3 types financial statements prepared by NFP’s. 5. Discuss the oversight bodies for NFP’s 6. Discuss the accounting for contributed services. 7. Describe the presentation of cash on the financial statements of NFP’s. Include in your answer a discussion of the...
Please answer the following questions: 1. a) What is a basket purchase? b) How are you...
Please answer the following questions: 1. a) What is a basket purchase? b) How are you supposed to account for basket purchases? What are the options, if any? c) What is a ‘business combination? What are the procedures for its accounting? d) What is goodwill? How do you calculate it? Is it amortized? What FASB regulates its treatment? (be specific!) 2. As an individual with available liquidity on hand you have a choice to make an investment in a company....
Microeconomics Answer all Questions Table 1 Price Quantity Demanded Quantity Supplied $10 10 60 $8 20...
Microeconomics Answer all Questions Table 1 Price Quantity Demanded Quantity Supplied $10 10 60 $8 20 45 $6 30 30 $4 40 15 $2 50 0 1   Refer to Table 1. The equilibrium price and quantity, respectively, are a. $2 and 50. b. $6 and 30. c. $6 and 60. d. $12 and 30. 2. .   Refer to Table 1. If the price were $8, a a. shortage of 20 units would exist and price would tend to rise. b. surplus of...
WEEK 10 DISCUSSION: Answer the following questions: Describe the types of software and systems that IT...
WEEK 10 DISCUSSION: Answer the following questions: Describe the types of software and systems that IT services firms produce. What is an ERP system? Why is the installation of these systems one of the harder challenges for a PM team? Why is a contract a special document? How is it treated differently from other documents?
Unit 1-3 Discussion: Please answer one or more of the following questions. 1) For what data...
Unit 1-3 Discussion: Please answer one or more of the following questions. 1) For what data in your professional or personal life would it be useful to construct a frequency table or histogram? If you give this some thought, you should be able to identify several sets of data. 2) After using the formula for determining the value of P16 (the 16th percentile) in a data set, the result is L = 5 (this whole number was obtained without rounding)....
Please answer questions 1-3 and fill out both charts columns ( Different and % Change) as...
Please answer questions 1-3 and fill out both charts columns ( Different and % Change) as well as the (percentage). I can't award credit if all questions and charts are not completed. Balance sheet data for Silver Corporation are presented here. Using Comparative Analysis SILVERT CORPORATION Balance Sheet December 31 Different % Change 2012 2011 ASSET Cash $                28,000 $             20,000 Receivable (net) 70,000 62,000 Other current assets 90,000 73,000 Long-term investment 62,000 60,000 Plant and equipment (net) 510,000 470,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT