Write a Program Segment: Write a C++ program that reads two integer values from
ID: 3723830 • Letter: W
Question
Write a Program Segment: Write a C++ program that reads two integer values from the user and prints their integer quotient and remainder. A sample run of the program might be (input shown in boldface italic). The user may NOT necessarily enter 57 and 8 as input: 1. Enter the dividend: 57 Enter the divisor: 8 The quotient is 7. The remainder is1. NOTE: You may NOT do the calculation of quotient and remainder in the cout statement. In other words, you need to declare two variables like quotient and remainder and calculate the values of these variables from the input values entered by the user. 2. Consider that an European tourist is visiting America. The tourist reads the weather report to decide how to dress for the day. However, the temperature is reported in Farenheit. Analyze this problem and provide the algorithm needed. Hint: Celsius 519 * (Fahrenheit - 32); Also, consider what occurs with integer divide. Write the C++ code for the above algorithm. Consider the following input output screen with a sample data (in bold): 3. What is the temperature in Farenheit? 67 The Celcius equivalent will be: 19.44Explanation / Answer
1)
#include <iostream>
using namespace std;
int main() {
int divisor, dividend, quotient, remainder;
cout << "Enter dividend: ";
cin >> dividend;
cout << "Enter divisor: ";
cin >> divisor;
quotient = dividend / divisor;
remainder = dividend % divisor;
cout << "The Quotient is = " << quotient << endl;
cout << "The Remainder is = " << remainder;
}
2)
in CPP division operator is (/) .The behavior of this operator depends on the type of the operands we are using to calculate.
If both operands are integers, C++ will performs concept called integer division. That means
any fractional part of the value will be removed and we will get integer outout
3)
#include <iostream>
using namespace std;
int main() {
float fahrenheit, celsius;
cout << "What is the temperature in fernehit : ";
cin >> fahrenheit;
celsius = ((float)5/9)*(fahrenheit - 32);
cout << "Celsius equvivalent will be : " << celsius << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.