473,414 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Need Help writing a program...don't know where to start

All the basic stuff I get like cin/cout...but the interpolation formula, the for/while loop, and reading in the desired altitude...i dont get it....please help...anybody

here are the directions I got:

The program is supposed to determine the pressure, temperature, and density, by linear interpolation of atmospheric conditions given in a data table(a text file).
1. Read in the data table and store these table values in a 4 one dimensional arrays.
2.Declare a character variable, which takes on the value of c or q. 'c' is for continue and 'q' is for quit.
3.Print out (on screen) a request to enter the desired altitude.
4.Read in the desired altitude.
5.Use a for loop to establish the nearest altitude interval and the table properties to be used in the interpolation formula.
The interpolation formula is: y=y1+(z-z1)x(y2-y1)/(z2-z1)
where y represents any one of the variables of interest and z the altitude.
6.Print out to screen, the altitude z, and the interpolated values of pressure p, temperature t, and density rho, at specified altitudes. The output should identify which value goes with which variable. Also include the units of the variable.
7.Print out to screen the following statements 'do you wish to continue or quit'. On a new line print out 'enter c or q to continure or quit.
8.Enter 'c' or 'q'.
9 Use a while loop to cover a list of altitudes the user may wish to enter. You may need to initialize the character variable before the while loop.
Oct 11 '06 #1
5 1884
All the basic stuff I get like cin/cout...but the interpolation formula, the for/while loop, and reading in the desired altitude...i dont get it....please help...anybody

here are the directions I got:

The program is supposed to determine the pressure, temperature, and density, by linear interpolation of atmospheric conditions given in a data table(a text file).
1. Read in the data table and store these table values in a 4 one dimensional arrays.
2.Declare a character variable, which takes on the value of c or q. 'c' is for continue and 'q' is for quit.
3.Print out (on screen) a request to enter the desired altitude.
4.Read in the desired altitude.

cin can read directly any of the built-in types, so try something like (assuming the altitude is float; it should work for double, long double, etc)

float altitude;
cin >> altitude;

5.Use a for loop to establish the nearest altitude interval and the table properties to be used in the interpolation formula.
The interpolation formula is: y=y1+(z-z1)x(y2-y1)/(z2-z1)
where y represents any one of the variables of interest and z the altitude.

One way to do is putting the altitudes in a float vector and iterate through it like this:

vector <float> altitudesVector; // You'll need to #include <vector>
/* Read the file and load the values as float in the vector. The way to do it
* depends on the particular format of your input file. Once that is done... */

float smallestDifference = abs(altitude-altitudesVector[0]);
float nearestAltitude = altitudesVector[0];
for(int i = 1; i < altitudesVector.size() ; i++)
if ( abs(altitude-altitudesVector[i])<abs (altitude-nearestAltitude) )
nearestAltitude = altitudesVector[i];

6.Print out to screen, the altitude z, and the interpolated values of pressure p, temperature t, and density rho, at specified altitudes. The output should identify which value goes with which variable. Also include the units of the variable.
7.Print out to screen the following statements 'do you wish to continue or quit'. On a new line print out 'enter c or q to continure or quit.
8.Enter 'c' or 'q'.
9 Use a while loop to cover a list of altitudes the user may wish to enter. You may need to initialize the character variable before the while loop.
char goOn = 'Y';
while(goOn != 'N'){
cout << "Input an altitude: " << endl;
float altitude;
cin >> altitude;
cout << "Any more? Y/N " << endl;
cin >> goOn;
}
Oct 11 '06 #2
so, i'm trying to put 1 and 1 together but I still think its not even close to being correct...here is what I have :

# include<fstream.h>
# include<iostream.h>
# include<stdio.h>
# include<math.h>
# include<stdlib.h>
# include <vector>

double alt[101],temp[101],rho[101],press[101];
int i, ie;
char c, q;
main()
{
ifstream inf;
inf.open("atm7.txt",ios::in);
cout << "Enter Desired altitude: " << endl;
float altitude;
cin >> altitude;

char goOn = 'c';
while(goOn != 'q')

{
cout<<"Do you wish to continue or quit\n";
cout <<"Enter 'c' to continue or 'q' to quit\n" << endl;
cin >> goOn;
}

float smallestDifference = abs(altitude-altitudesVector[0]);
float nearestAltitude = altitudesVector[0];

for(int i = 0; i <=100,000 ; i+=1000)
if ( abs(altitude-altitudesVector[i])<abs (altitude-nearestAltitude) ) nearestAltitude = altitudesVector[i];
Oct 11 '06 #3
D_C
293 100+
1. Read in the data table, store it, etc.

You say you figured out the cin, cout out, but what about the file I/O? I assume you have figured that out. Also, I assume that data is sorted by altitude, in ascending order.

9 Use a while loop to cover a list off altitudes the user may wish to enter. You may need to initialize the character variable before the while loop.

I'm not sure what this is asking for. I've done enough anyways, you can figure out the rest.

Expand|Select|Wrap|Line Numbers
  1. char input = '\0';
  2. float altitude = 0.0f;
  3. float temp = 0.0f;
  4. float rho = 0.0f;
  5. float press = 0.0f;
  6.  
  7. do
  8. {
  9.   cout << "Enter desired altitude: ";
  10.   cin >> altitude;
  11.  
  12.   int i;
  13.   for(i = 0; (i < altitude.length()-1) && (altitude[i] <= z); i++);
  14.  
  15.   if(i > 0)
  16.     i--;
  17.  
  18.  
  19.   temp = temp[i] +(altitude-altitude[i])*(temp[i+1]-temp[i])/(altitude[i+1]-altitude[i]);
  20.  
  21.   rho = // you do this one
  22.   press = // and this one too
  23.  
  24. // I'm not sure what units you are using, you'll need to fix those
  25.   cout << "Altitude:\t" << altitude << " altitude units (m ?)\n"
  26.        << "Temperature:\t" << temp << " ºF/C\n"
  27.        << "Temperature:\t" << rho << " density units (kg/m^3 ?)\n"
  28.        << "Temperature:\t" << press << " pressure units (kPa ?)\n\n";
  29.  
  30.   do
  31.   {
  32.     cout << "Do you wish to continue or quit? ";
  33.     cin >> input;
  34.   } while(input != 'c' || input != 'q')
  35. } while(input != 'q')
Oct 12 '06 #4
I wrote the program and the complier at school is Microsoft Visual 6.0.......but i keep getting one error message and i have no idea what it means...i bolded the line where it occurs n the error message i get....

# include<fstream.h>
# include<iostream.h>
# include<stdio.h>
# include<math.h>
# include<stdlib.h>





main()
{
double alt[105],temp[105],rho[105],press[105],desalt[105];
double z = 0.0f;
double p = 0.0f;
double t = 0.0f;
double r = 0.0f;
int i, ie;
char c, q, input;



ifstream inf;
inf.open("atm7.txt",ios::in);
i=1;

while (!inf.eof())
{
inf>>alt[i]>>temp[i]>>rho[i]>>press[i];
i++;
}
ie=i-1;


L1:;
printf("Enter Desired altitude: ");
error C2679: binary '>>' : no operator defined which takes a right-hand
operand of type 'double [105]' (or there is no acceptable conversion)
--------> cin>> desalt>>endl;
printf("Desire altitude: ");
cout<<desalt<<endl;


for(i = 0; (i <=100000) && (alt[i]<= z); i+=1000);
{
t= temp[i] +(z-alt[i])*(temp[i+1]-temp[i])/(alt[i+1]-alt[i]);
r= rho[i] +(z-alt[i])*(rho[i+1]-rho[i])/(alt[i+1]-alt[i]);
p= press[i] +(z-alt[i])*(press[i+1]-press[i])/(alt[i+1]-alt[i]);

printf("Altitude (ft):\t");
cout<<alt <<endl;
printf("Pressure (lb per in^2):\t");
cout<< p <<endl;
printf("Temperature (F):\t");
cout<< t <<endl;
printf("Density (lb per ft^3):\t");
cout<< r <<endl;
}

do

{
printf("Do you wish to continue or quit?");
cin >> input;
}
while(input!='q'); goto L1;


return 0;

}
Oct 13 '06 #5
Etaks
7
Im kinda new to programming, and i REALLY dont know if im right (probably not) but i think the problem lies in this << or >>, try spaces in between as i saw a line where this happened (cout<<(text)<<endl;), dont flame me if im wrong
Oct 16 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: coolcsgeek | last post by:
i took a c++ intro cs course a few years back and recently decided to major in cs after much switching back and forth between majors. it seems my school has replaced most of it's intro level cs...
28
by: Jed | last post by:
Hello to all! I have a couple of projects I intend starting on, and was wondering if someone here could make a suggestion for a good compiler and development environment. My goals are as...
17
by: Eric Lindsay | last post by:
Is learning to write CSS a better use of time than finding and using a package that produces complete web pages? I've moved to a new platform (Macintosh), taking with me about 400 personal web...
11
by: abico | last post by:
Write a program that reads in a sequence of words and prints them in reverse order.Using STACK.
13
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
1
by: Tony Freixas | last post by:
Hello, I'm trying to create a wrapper for a program. I want to execute program 'X' by running program 'Y', such that 'Y' appears to function pretty much like 'X' both in the way command line...
6
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """...
5
by: alck1234 | last post by:
Hi, I need help on my mini project on object orientated programming. The question goes like this: A mini-mart has just installed a bar code reader to improve efficiency at their checkouts....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.