Comp Sci How can C++ be used to solve various programming problems?

  • Thread starter Thread starter Norah
  • Start date Start date
  • Tags Tags
    C++
AI Thread Summary
C++ can be effectively utilized to solve various programming problems, such as calculating temperature based on depth, classifying aircraft types, analyzing rainfall data, and processing arrays of numbers. The discussion highlights specific problems requiring user-defined functions, including temperature conversion formulas and aircraft classification based on speed and length. Additionally, participants emphasize the importance of understanding the concepts rather than just seeking answers, suggesting that examples and tutorials can aid in grasping the necessary skills. The conversation also includes sample code snippets to illustrate programming techniques relevant to the problems presented. Overall, the focus is on applying C++ fundamentals to tackle practical challenges.
Norah
Messages
4
Reaction score
0
PLZZZZZ HELP ME
I am crying I have a test
but, I don't know how to solve this problems
PLEASSSSSSSSE HELP

Problem#1:

Write user-defined function to take a depth (in kilometers) inside the Earth as input data; compute and print the temperature at this depth in degree Celsius and degree Fahrenheit. Write main program to call this function.
Relevant Formulas

Celsius=10(depth)+20.

Fahrenheit=1.8 (Celsius)+32.

Problem#2:

The Air Force has asked you to write a program to label supersonic aircraft as military or civilian. Your program is to be given the plane's observed speed in km/h and its estimated length in meters.

For planes traveling in excess of 1100 km/h, you will label those longer than 52 meters "civilian" and shorter aircraft as "military". For planes traveling at slower speeds, you will issue an "aircraft type unknown" message.

Problem#3:

Consider the following list of monthly rainfall in a city in millimeters.

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
11.5 10.6 9.8 3.7 8.5 14.0 18.5 22.4 27.6 12.5 12.0 13.8

Use an array with above data. It is desired to determine the month in which maximum and minimum rainfall occurred. Also find the average monthly rainfall and its standard deviation. Instead of actual names you can just print the number of month ranging from 1-12. No user input is required.

R is the average rainfall and ri are monthly rainfalls.


Problem#4:

Twenty-five numbers are entered from the keyboard into an 1-D array. Write a C++ program to find out how many of them are positive, how many are negative, how many are even and how many odd.

Problem#5:

Write a complete C++program that takes the length and width of a rectangular yard and the length and width of a rectangular house situated in the yard. Your program should calculate and display the time required to cut the grass at the rate of two squire feet a second.
 
Last edited:
Physics news on Phys.org
What have you tried already?

Problem 1, for example, is very basic. If you have ever done anything in C++ at all, you must have some idea how to do it?

[edit]There you go: someone even solved one for you. Just asking for answers isn't going to help you do your test though...[/edit]
 
Many of us would love to help. But we need to see what you have before we can do anything! Where do you get stuck?
 
I'm sorry my solutions were removed. It's sort of a shame, since I think what you really need are a few solid examples to work from. I guess I would recommend looking at some simple tutorials on Google for c++. For instance, here's a program that doesn't answer any of your questions, but contains all the ideas you'll need to solve a couple...

Code:
#include <iostream>
using namespace std;

void getSpeedProc()
{
   double time, mph, kph;

   cout << "Please enter the time, in hours, taken to travel 3mi = 5km:" << endl;
   cout << "   time = ";
   cin >> time;

   mph = 3.0 / time;
   kph = mph * (5.0 / 3.0); // to convert from kph to mph, multiply by 5/3

   cout << "The speed is:" << endl;
   cout << "   speed = " << mph << " miles per hour" << endl;
   cout << "   speed = " << kph << " kilometers per hour" << endl;
}

void isDuckProc()
{
   double weight, quacks;

   cout << "Please enter how much it weighs, in pounds:" << endl;
   cout << "   weight = ";
   cin >> weight;

   cout << "Please enter how many times you heard it quack:" << endl;
   cout << "   quacks = ";
   cin >> quacks;

   if(weight > 25.0)
   {
      cout << "Cannot classify this animal..." << endl;
   }
   else
   {
      if(quacks > 5)
      {
         cout << "This must be a duck!" << endl;
      }
      else
      {
         cout << "This is a goose, or something..." << endl;
      }
   }
}


int main()
{
   getSpeedProc(); // calculates speeds...

   isDuckProc(); // determines whether something is a duck...

   return 0;
}

Your guess is as good as mine as to which problems these can serve as models for. I'll get to the others later. Best of luck!
 

Similar threads

Replies
1
Views
10K
Replies
7
Views
3K
Replies
3
Views
2K
Replies
15
Views
2K
Replies
23
Views
3K
Replies
4
Views
2K
Back
Top