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

  • Context: Comp Sci 
  • Thread starter Thread starter Norah
  • Start date Start date
  • Tags Tags
    C++
Click For Summary

Discussion Overview

The discussion revolves around various programming problems that require solutions using C++. Participants are seeking assistance with specific coding tasks, including user-defined functions, conditional logic, array manipulation, and calculations based on user input.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • Post 1 outlines multiple programming problems, including calculating temperature based on depth, classifying aircraft, analyzing rainfall data, counting positive and negative numbers in an array, and calculating time to cut grass in a yard.
  • Post 2 questions the original poster's attempts at solving the problems, suggesting that they should have some foundational understanding of C++ to tackle the tasks.
  • Post 3 expresses a willingness to help but emphasizes the need for the original poster to share their current progress or specific areas of difficulty.
  • Post 4 provides a sample C++ program that demonstrates basic programming concepts, although it does not directly address the original problems. The poster suggests that the example may contain useful ideas for the original poster's tasks.

Areas of Agreement / Disagreement

Participants generally agree on the need for the original poster to demonstrate their current understanding and progress. However, there is no consensus on specific solutions to the problems presented, and multiple viewpoints on how to assist the original poster are evident.

Contextual Notes

Participants have not resolved the specific programming problems, and there are varying levels of familiarity with C++ among those contributing to the discussion.

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 ·
Replies
1
Views
11K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
Replies
9
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 11 ·
Replies
11
Views
4K