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

  • Comp Sci
  • Thread starter Norah
  • Start date
  • Tags
    C++
In summary, the conversation discusses various programming problems and potential solutions for a test. These include writing a user-defined function to calculate temperature, labeling aircrafts, analyzing rainfall data, counting positive and negative numbers in an array, and calculating grass-cutting time for a rectangular yard and house. The conversation also mentions the need for the individual to try attempting these problems before seeking help.
  • #1
Norah
4
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
  • #2
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]
 
  • #3
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?
 
  • #4
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!
 

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

1. What is the purpose of "Norah" in C++?

"Norah" is not a predefined term or keyword in C++. It could be a variable, function, or object defined by the programmer for a specific purpose in their code.

2. How do you use "Norah" in a C++ program?

The usage of "Norah" would depend on how it is defined in the program. It could be used as a variable to store data, a function to perform a specific task, or an object to represent an entity.

3. Is "Norah" a standard library in C++?

No, "Norah" is not a standard library in C++. Standard libraries are predefined collections of functions and classes that can be used in a C++ program without having to write them from scratch.

4. Can "Norah" be used in any other programming languages?

The term "Norah" itself is not specific to any programming language. It could be used in other languages as well, but its functionality and usage would depend on the syntax and rules of that particular language.

5. Are there any resources available to learn more about "Norah" in C++?

Since "Norah" is not a predefined term in C++, there may not be specific resources available on it. However, there are various online forums and communities where programmers can discuss and share their knowledge on different aspects of C++ programming, including the usage of custom variables and functions like "Norah".

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
Replies
17
Views
2K
Back
Top