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.
5 1891
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 smallestDiffere nce = 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;
}
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<iostrea m.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 smallestDiffere nce = 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];
D_C 293
Contributor
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. - char input = '\0';
-
float altitude = 0.0f;
-
float temp = 0.0f;
-
float rho = 0.0f;
-
float press = 0.0f;
-
-
do
-
{
-
cout << "Enter desired altitude: ";
-
cin >> altitude;
-
-
int i;
-
for(i = 0; (i < altitude.length()-1) && (altitude[i] <= z); i++);
-
-
if(i > 0)
-
i--;
-
-
-
temp = temp[i] +(altitude-altitude[i])*(temp[i+1]-temp[i])/(altitude[i+1]-altitude[i]);
-
-
rho = // you do this one
-
press = // and this one too
-
-
// I'm not sure what units you are using, you'll need to fix those
-
cout << "Altitude:\t" << altitude << " altitude units (m ?)\n"
-
<< "Temperature:\t" << temp << " ºF/C\n"
-
<< "Temperature:\t" << rho << " density units (kg/m^3 ?)\n"
-
<< "Temperature:\t" << press << " pressure units (kPa ?)\n\n";
-
-
do
-
{
-
cout << "Do you wish to continue or quit? ";
-
cin >> input;
-
} while(input != 'c' || input != 'q')
-
} while(input != 'q')
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<iostrea m.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<<e ndl;
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("Altitud e (ft):\t");
cout<<alt <<endl;
printf("Pressur e (lb per in^2):\t");
cout<< p <<endl;
printf("Tempera ture (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;
}
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 courses to
java making c++ obsolete! whether this is a good idea or not that is a
discussion for another day. anyway learning a new language is...
|
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 follows:
1. Develop the project code on XP.
|
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 pages, some dating back so far I probably wrote them in vi.
About 4 years ago (thanks in part to hints found in this group) I
converted about 80...
|
by: abico |
last post by:
Write a program that reads in a sequence of words and prints them in
reverse order.Using STACK.
|
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 month. We are assuming that the year will be
valid 4 digit integer.
So you don't have to think much about that(in terms of validation)
except for...
| |
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 the
instructions and couldnt get the correct results. heres the code
stuff...
temperature=input("what is the temperature of the spam?")
if...
|
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 options are handled
and the way input, output and error messages are reported. Program 'X'
is a console application.
I had it pretty well figured...
|
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?
"""
-----------------------------------------------------------------------------
Name: _writePythonCode.py
Purpose: This script writes Python code and thentransfers control to it.
...
|
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.
Assume that the bar code is to access a file that store the product
descriptions, unit price
and quantity of each product sold in the shop. Assume that...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |