Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++. additional Control Structures // Program Convert converts a temperature from Fahrenheit to // Celsius or a temperature from Celsius to Fahrenheit // depending on
C++. additional Control Structures
// Program Convert converts a temperature from Fahrenheit to
// Celsius or a temperature from Celsius to Fahrenheit
// depending on whether the user enters an F or a C.
#include
using namespace std;
int main ()
{
char letter; // Place to store input letter
int tempIn; // Temperature to be converted
int tempOut; // Converted temperature
cout
cout
cout
cout
cout
cin >> letter;
while (letter != 'Q')
{
cout
cin >> tempIn;
if (letter == 'F')
{
tempOut = 5 * (tempIn - 32) / 9;
cout
}
else
{
tempOut = (9 * tempIn / 5) + 32;
cout
}
cout
cin >> letter;
}
return 0;
}
-
Lopping
// Program Looping uses a count-controlled loop to read and
// sum 10 integer values and an event-controlled loop to
// read and sum values until a negative value is found.
// The data is on file Looping.dat.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
int value;
int counter;
int sum;
inData.open("looping.dat");
counter = 1;
sum = 0;
while (counter
{ // Ten values read and summed
inData >> value;
sum = sum + value;
counter++;
}
cout
Exercise 1: Compile and run program Looping, Fill in the following table. First sum: Second sum: Exercise 2: Program Looping contains two loops implemented with while statements. Rewrite program Looping, replacing the while statements with do-while statements. Fill in the following table. First sum: Second sum:- Exercise 3: Can program Looping be rewritten using a for statement for each loop? Explain. Exercise 4: Rewrite program Looping using a for statement to implement the count- controlled loop. Fill in the following table. First sum: Second sum: Exercise 5: Rerun your program using data file looping.d2. Describe what happens r an error condition was generated, correct your program and rerun the program. Fill in the following table. First sum: Second sum inData >> value;
sum = 0;
while (value >= 0)
{ // Values are read and summed until a negative is read
sum = sum + value;
inData >> value;
}
cout
return 0;
}
Looping.data file
1066
1492
1977
1947
1953
1066
1668
1935
1926
1492
1066
1492
1977
1947
1953
1066
1668
1935
1926
1492
-1500
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started