Watermelon Problem:
The answer should not include any whitespace.
#include<iostream>
using namespace std;
int main()
{
double distance, gravity =9.8, height;
int time, t=0;
cout<<"Please input the time of fall
in seconds:"<<endl;
[ A ] // Get the user input of the
time of fall in seconds (Use cin>>
method)
cout<<endl;
cout<<"Please input the height of the
bridge in meters:"<<endl;
[ B ] // Get the user input of the
height of the bridge in meters (Use cin>>
method)
cout<<endl;
cout<<"Time Falling (seconds)\t
Distance Fallen(meters)"<<endl;
while( [ C ] ) { //Write the while
loop condition that iteration executes while t is less
than equal time
distance = 0.5 * gravity
* ((double)t*(double)t);
if(distance >
height){
cout<<t<<"\t"<<distance<<endl;
cout<<"Warning-Bad
Data: The distance fallen exceeds the height of the
bridge"<<endl;
break;
}else{
cout<<t<<"\t"<<distance<<endl;
t++;
}
}
return 0;
}
Fill Out [A], [B], and [C]
Program: (program after filling in A,B,C)
#include<iostream>
using namespace std;
int main()
{
double distance, gravity =9.8, height;
int time, t=0;
cout<<"Please input the time of fall in
seconds:"<<endl;
//[ A ] // Get the user input of the time of fall in
seconds (Use cin>> method)
cin>>time;
cout<<endl;
cout<<"Please input the height of the bridge
in meters:"<<endl;
//[ B ] // Get the user input of the height of the
bridge in meters (Use cin>> method)
cin>>height;
cout<<endl;
cout<<"Time Falling (seconds)\t Distance Fallen(meters)"<<endl;
while( t<=time )
{ //Write the while loop condition that iteration
executes while t is less than equal time
distance = 0.5 * gravity *
((double)t*(double)t);
if(distance > height)
{
cout<<t<<"\t"<<distance<<endl;
cout<<"Warning-Bad Data: The distance fallen exceeds the
height of the bridge"<<endl;
break;
}
else
{
cout<<t<<"\t"<<distance<<endl;
t++;
}
}
system("pause");
return 0;
}
Output:
Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {...
#include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...
C++ Programming Windows Application Console Student Generated Problem Option 2.5 Option 2.5: Suppose Dave drops a watermelon off a high bridge and lets it fall until it hits the water. If we neglect air resistance, then the distance d in meters fallen by the watermelon after t seconds is d 0.5 g* t where the acceleration of gravity 9.8 meters/second?. Write a program that asks the user to input the number of seconds that the watermelon falls and the height...
Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() { string first, last, job; double hours, wages, net, gross, tax, taxrate = .40; double oPay, oHours; int deductions; // input section cout << "Enter First Name: "; cin >> first; cout << "Enter Last Name: "; cin >> last; cin.ignore(); cout << "Enter Job Title: "; getline(cin, job); cout << "Enter Hours Worked:...
#include <iostream> using namespace std; int main() { int sumOdd = 0; // For accumulating odd numbers, init to 0 int sumEven = 0; // For accumulating even numbers, init to 0 int upperbound; // Sum from 1 to this upperbound // Prompt user for an upperbound cout << "Enter the upperbound: "; cin >> upperbound; // Use a loop to repeatedly add 1, 2, 3,..., up to upperbound int number =...
#include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...
#include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...
#include <iostream> #include <cmath> using namespace std; int main() { int x; int y; int z; int r1; int r2; cin >> x; cin >> y; cin >> z; r1 = 4* pow(x,3)-5*pow(y,2)+3*z; r2 = r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << "r1="; cout << 4* pow(x,3)-5*pow(y,2)+3*z; cout << endl; cout << "r2="; cout << r1+7*pow(x,3)-2*pow(y,2)+11*z; cout << endl; cout << "r3="; cout << r2-9*pow(x,3)+22*pow(y,2)-6*z; cout << endl; return 0; } 1-115 Your output r2-395 13-186 5:Compare output Output differs. See highlights below. -163...
#include <iostream> using namespace std; int main(void) { int SIZE; cout<<"Enter the size of the array"<<endl; cin>>SIZE; int *numlist = new int[SIZE]; // Read SIZE integers from the keyboard for (int i = 0; i<SIZE; i++ ) { cout << "Enter value #" << i+1 << ": "; cin >> numlist[i]; } // Display the numbers in a reverse order for (int i = SIZE; i > 0; i--...
Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0, ave-ee, int locmx, locmn int n; cout <<"Enter the number of students: "<<endl; cin >> ni double listln]; double max-0; double min-e; for (int i-e ; i<n ;i++) cout<s enter the gpa: "<cendli cin>>listli]; while (listlile i listli1>4) cout<s error,Try again "<cendl; cin>listlil: sun+=list[i]; N1 if (listli]>max) for(int isin itt) max=list [i]; 10cmx=1+1 ; else if (list [i] min) min=list [i]; locmn-i+1; ave sum/n;...
FILL IN THE BLANKS #include #include <> *BLANK* using namespace std; int main() { const double HOURLY_RATE = 15; string input_str; cout << "Enter days of attendance: " << endl; *BLANK* (cin, input_str); stringstream input_stream(); int total_hours = 0; while(!input_stream.())*BLANK* { int hours; string day; input_stream >> day; if(day == *BLANK*|| day == *BLANK*) { hours = 5; } *BLANK*(day == "Tuesday" || day == "Thursday") { hours = 4; } else if(day ==...