Posts

Showing posts from September, 2020

Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days

Image
(Find the number of years) Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For  simplicity, assume a year has 365 days. #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { int minutes; cout<< "enter the minutes : " ; cin>>minutes; const int year_per_minutes=365*24*60; const int day_per_minutes=24*60; int year=minutes/year_per_minutes; int day=(minutes%year_per_minutes)/(day_per_minutes); cout<< " " <<minutes<< " minutes is aproximately " <<year<< " years and " <<day<< " days" ; return 0; } copy Output enter the minutes : 1000000000  1000000000 minutes is aproximately 1902 years and 214 days [Program finished] Need of Programmer Need of Programmer

ShowCurrenttime gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in the specified time zone.

Image
(Current time) ShowCurrenttime gives a program that displays the  current time in GMT. Revise the program so that it prompts the user to enter the time  zone offset to GMT and displays the time in the specified time zone.  #Beginner #Intermediate In gcc c++ compiler using namespace std; #include<iostream> #include<ctime> using namespace std; int main() { int totalsec = time(0); int currentsec = totalsec % 60; int totalminutes= totalsec / 60; int currentminutes=totalminutes % 60; int totalhrs=totalminutes / 60; int currenthrs=totalhrs % 24; int gmt; cout<< "enter GMT zone -12 to +12 :" ; cin>>gmt; int currentgmthrs=(totalhrs+gmt)%24; cout<< "main time  " <<currenthrs<< " :" <<currentminutes<< " :" <<currentsec<< " GMT +0" <<endl; cout<< "your time " <<currentgmthrs<< " :" <<currentm

Average acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula:

(Physics: acceleration) Average acceleration is defined as the change of velocity  divided by the time taken to make the change, as shown in the following formula: a = (v1 - v0)/t  Write a program that prompts the user to enter the starting velocity v0 in meters/ second, the ending velocity v1 in meters/second, and the time span t in seconds, and  displays the average acceleration.  #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { float  velocity1,velocity0,time,acceleration; cout<< "Enter velocity0 m/s velocity1 m/s time /s :" ; cin>>velocity0>>velocity1>>time; acceleration=(velocity1-velocity0)/time; cout<< "The avrage acceleration is " <<acceleration; return 0; } copy Output Enter velocity0 m/s velocity1 m/s time /s :5 50 4 The avrage acceleration is 11.25 [Program finished] Need of Programmer Need of Pro

Write a program that calculates the energy needed to heat water from an initial temperature to a final temperature. Your program should prompt the user to enter the amount of water in kilograms and the initial and final temperatures of the water.

Image
(Science:calculating energy ) Write a program that calculates the energy needed to  heat water from an initial temperature to a final temperature. Your program should  prompt the user to enter the amount of water in kilograms and the initial and final  temperatures of the water. The formula to compute the energy is Q = M * (finalTemperature – initialTemperature) * 4184  where M is the weight of water in kilograms, temperatures are in degrees Celsius, and  energy Q is measured in joules.  #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { float M,finalTemperature,initialTemperature; cout<< "Enter te amount of water in kilograms :" ; cin>>M; cout<< "Enter the initial temperature :" ; cin>>initialTemperature; cout<< "Enter te finalTemperature :" ; cin>>finalTemperature; float Q=M*(finalTemperature-initialTemperature)*4184; cout<< "Th

Write a program that prompts the user to enter v in meters/second (m/s) and the acceleration a in meters/second squared (m/s²), and displays the minimum runway length.

Image
(Physics: finding runway length) Given an airplane’s acceleration a and take-off  speed v, you can compute the minimum runway length needed for an airplane to take  off using the following formula: length = v²/2a  Write a program that prompts the user to enter v in meters/second (m/s) and the accel- eration a in meters/second squared (m/s²), and displays the minimum runway length. #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { float speed,acceleration,length; cout<< "Enter speed and acceleration :" ; cin>>speed>>acceleration; length=( float )(speed*speed)/(2*acceleration); cout<< "The minimum runway length for this airplane is :" <<length; return 0; } copy Output Enter speed and acceleration :60 3.5 The minimum runway length for this airplane is :514.286 [Program finished] Need of Programmer Need of Programmer

Financial application c++ program

Image
(Financial application: compound value) Suppose you save $100 each month into a  savings account with the annual interest rate 5%. Thus, the monthly interest rate is  0.05/12 = 0.00417. After the first month, the value in the account becomes 100 * (1 + 0.00417) = 100.417   After the second month, the value in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252   After the third month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507   and so on.  Write a program that prompts the user to enter a monthly saving amount and displays  the account value after the sixth month #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { float amount,total=0; cout<< "Enter te monthly saving amount $ :" ; cin>>amount; total=amount*(1+0.00417); //1st total=(amount+total)*(1+0.00417); //2nd total=(amount+total)*(1+0.00417); //3rd total=(amount+total)*(1+0.00417); //4th tota

Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is

Image
(Geometry: distance of two points) Write a program that prompts the user to enter  two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is  √ (x2 - x1)²+ (y2 - y1)² . Note that you  can use pow(a, 0.5) to compute √a.  #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float x1,y1,x2,y2; cout<< "Enter x1 and y1 :" ; cin>>x1>>y1; cout<< "Enter x2 and y2 :" ; cin>>x2>>y2; float distance=pow((pow(x2-x1,2))+pow(y2-y1,2),0.5); cout<< "The distance between the two points is :" <<distance; return 0; } copy Output Enter x1 and y1 :1 9 Enter x2 and y2 :3 -5 The distance between the two points is :14.1421 [Program finished] Need of Programmer Need of Programmer

Write a program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon is

Image
(Geometry: area of a hexagon) Write a program that prompts the user to enter the  side of a hexagon and displays its area. The formula for computing the area of a  hexagon is  Area =(3√3 / 2)s². #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float side; cout<< "Enter the side :" ; cin>>side; float area=3*sqrt(3)*pow(side,2)/2; cout<< "the area of the hexagon :" <<area; return 0; } copy Output Enter the side :4 the area of the hexagon :41.5692 [Program finished] Need of Programmer Need of Programmer

How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed.

Image
  (Science: wind-chill temperature) How cold is it outside? The temperature alone is  not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed. The formula is: twc = 35.74 + 0.6215ta - 35.75v 0.16 + 0.4275tav 0.16  where ta is the outside temperature measured in degrees Fahrenheit and v is the speed measured in miles per hour. twc is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below –58°F or above 41°F.  Write a program that prompts the user to enter a temperature between –58°F and  41°F and a wind speed greater than or equal to 2 and displays the wind-chill temperature. Use pow(a, b) to compute v 0.16 #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<c

Write a program that displays the following table:

Image
(Print a table) Write a program that displays the following table: x        y       pow(x, y) 2.5   1.2    3.00281 5.0   2.4    47.5913 1.2   3.6    1.92776 2.4   5.0    79.6262 3.6   2.5    24.5899 #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { cout<< "x\t" << "y\t" << "pow(x,y)" <<endl; cout<<2.5<< "\t" <<1.2<< "\t" <<pow(2.5,1.2)<<endl; cout<<5.0<< "\t" <<2.4<< "\t" <<pow(5.0,2.4)<<endl; cout<<1.2<< "\t" <<3.6<< "\t" <<pow(1.2,3.6)<<endl; cout<<2.4<< "\t" <<5.0<< "\t" <<pow(2.4,5.0)<<endl; cout<<3.6<< "\t" <<2.5<< "\t" <<pow(3.6,2.5)<<endl; return 0; }

Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is

Image
(Geometry: area of a triangle) Write a program that prompts the user to enter three  points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula  for computing the area of a triangle is s = (side1 + side2 + side3)/2; area = 2√ s(s - side1)(s - side2)(s - side3) #Beginner In gcc c++ compiler using namespace std; #include<iostream> #include<cmath> using namespace std; int main() { float x1,y1,x2,y2,x3,y3; cout<< "Enter three point of triangle:" <<endl; cout<< "point1 x1 and y1 :" ; cin>>x1>>y1; cout<< "point2 x2 and y2 :" ; cin>>x2>>y2; cout<< "point3 x3 and y3 :" ; cin>>x3>>y3; float side1=sqrt(pow(x2-x1,2)+pow(y2-y1,2)); float side2=sqrt(pow(x3-x2,2)+pow(y3-y2,2)); float side3=sqrt(pow(x1-x3,2)+pow(y1-y3,2)); float s=(side1+side2+side3)/2; float area=sqrt(s*(s-side1)*(s-side2)*(s-side3)); cout<< "

Write a program that prompts the user to enter the coordinates of two points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).

Image
(Slope of a line) Write a program that prompts the user to enter the coordinates of two  points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two  points. The formula of the slope is (y2 - y1)/(x2 - x1).  #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { float x1,y1,x2,y2; cout<< "Enter the coordimnates for two points :\n" ; cout<< "x1 and y1 :" ; cin>>x1>>y1; cout<< "x2 and y2 :" ; cin>>x2>>y2; float slope; slope=(y2-y1)/(x2-x1); cout<< "The slope for te line that connects two points\n(" << "x1=" <<x1<< ",y1=" <<y1 << ",x2=" <<x2<< ",y2=" <<y2 << ") is " <<slope; return 0; } copy Output Enter the coordimnates for two points : x1 and y1 :1 2 x2 and y2 :7 5 The slope fo

Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI.

Image
(Health application: BMI) Body Mass Index (BMI) is a measure of health on  weight. It can be calculated by taking your weight in kilograms and dividing by the  square of your height in meters. Write a program that prompts the user to enter a  weight in pounds and height in inches and displays the BMI. Note that one pound is  0.45359237 kilograms and one inch is 0.0254 meters. #Beginner In gcc c++ compiler using namespace std; #include<iostream> using namespace std; int main() { const float KG_PER_POUND=0.45359237; const float METER_PER_INCH=0.0254; float pound,inch; cout<< "Enter weigth in pounds :" ; cin>>pound; cout<< "Enter heigth in inces :" ; cin>>inch; float bmi=( float )(pound*KG_PER_POUND)/((inch*METER_PER_INCH)*(inch*METER_PER_INCH)); cout<< "BMI is " <<bmi; return 0; } copy Output Enter weigth in pounds :95.5 Enter heigth in inces :50 BMI is 26.8573 [Program finished] Explor