Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,552 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,588 people online right now. Registration is fast and FREE... Join Now!




Linear Interpolation and arrays/functions

 
Reply to this topicStart new topic

Linear Interpolation and arrays/functions

SknknZmbie
30 Oct, 2007 - 09:38 PM
Post #1

New D.I.C Head
*

Joined: 30 Oct, 2007
Posts: 8


My Contributions
I need serious homework help...

Here is the exact homework assignment I have been given...it's due in twelve hours (time stamp 01:35 AM, OCT 31st) Due by 12:15AM EST OCT 31st.

Homework #6 ESC151 Fall 2007 Due Wednesday Oct. 31
Wind Tunnel, Linear Interpolation. Topics: arrays, functions.

The data file tunnel.txt contains two columns of data: the first column is the flight-path angle (in degrees), and the second column is the corresponding coefficient of lift. The flight-path angles will be in ascending order. Write a single C program that will perform the following tasks:
1. Read the data in tunnel.txt into two 1-dimensional arrays, angle and lift. Use the EOF method for reading data. Program should include the NULL statement to verify that the file is present.
2. Prompt the user to enter a flight-path angle. If the angle is out of range of the data, print a message and have them enter another value. If the angle is within range, use linear interpolation (see section 2.5 of the text) to determine the expected coefficient of lift for that angle.
3. The interpolation should be done within a function. The function should also check if the requested angle exactly matches one of the angles in the data file. If it does match, there is no need to do an interpolation. Instead, print a message and return the coefficient of lift value to the main program. If interpolation is done, the interpolated coefficient of lift is returned to the main program.
4. In the main program, print the angle requested, and coefficient of lift.
5. Your main program should prompt the user to enter an angle three times (not including any invalid entries).
6. Write all the results to an output file. At the top of the output file, your program should write your name, section number, and homework #6.
7. Test your program using the following angles: 5, 25, 12, -10, 9
_________________________________________________________________
Requirements:
• Email your source code (lastname.cpp) to Pruk due 5 pm on the due date. Subject line: HW6 Section number Lastname
• Hand in hardcopies of your source code (lastname.cpp) and output file stapled together. If your program does not run correctly, please indicate this in writing on the source code hardcopy. Indicate whether you are getting compiler errors and/or warnings, run-time errors, and/or incorrect results.
Only the hardcopy will be graded. A select number of electronic programs will be executed and reviewed. Your electronic file must correspond to the hardcopy handed in.

Grading scale for homework (10 points maximum):
5 points: program executes correctly according to given directions
1 points: electronic source code, corresponding to hardcopy
1 points: proper style, formatting, and comments
3 points: code is efficient and follows specifications


Please help me...I'm supposed to be an engineer but I don't f*cking get this...F*ck...

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Linear Interpolation And Arrays/functions
30 Oct, 2007 - 10:07 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
I'm truly sorry but here at </dream.in.code> we're not going to do your homework for you, you can read the Forum Rules for more information on this. It is a policy of </dream.in.code> that you provide code that you have written to attempt to solve your homework assignment before we will offer help (and this is strictly enforced). Also, its probably good practice to ask for help much more than 12 hours before the assignment is due.

Next, this line in your assignment

QUOTE

Write a single C program that will perform the following tasks:


Tells me you have also posted this in the wrong forum, this should be in the C and C++ Forum so I will move it there for you smile.gif
User is online!Profile CardPM
+Quote Post

SknknZmbie
RE: Linear Interpolation And Arrays/functions
31 Oct, 2007 - 04:41 AM
Post #3

New D.I.C Head
*

Joined: 30 Oct, 2007
Posts: 8


My Contributions
I apologize for my last post not following the rules. But here is my code that I have so far... along with the data to be read.

CODE
#include "stdio.h"
#include "math.h"
#define N 17
#define TUNNEL "tunnel.txt"
#define OUTPUT "output.txt"

int main(void)
{
    /* Declare and initialize variables. */
    int k=0, npts, angle_x;
    double angle[N];
    double lift[N];
    double a, b, c;
    double f(double x[ ], double y[ ]);
    FILE *tunnel;
    FILE *output;
        
    tunnel=fopen("tunnel.txt","r");
    output=fopen("output.txt","w");
    if (tunnel == NULL)
        printf("Error opening file");
    else
    {
        fprintf(output,"Ryan Primiano, 2422240, Sec 2, Homework006\n");
        fscanf(output,"%lf %lf",&angle[k],&lift[k]);

        printf("Enter a flight-path angle: \n");
        scanf("%i",&angle_x);

        while ((fscanf(tunnel,"%lf %lf",&angle[k],&lift[k]))==2)
        {
            fprintf(output,"%.f %.3f\n",angle[k],lift[k]);
        }
    }
    return 0;
}



tunnel.txt
CODE
-4    -0.182
-2    -0.056
0    0.097
2    0.238
4    0.421
6    0.479
8    0.654
10    0.792
12    0.924
14    1.035
15    1.076
16    1.103
17    1.120
18    1.121
19    1.121
20    1.099
21    1.059


Thank you for your time. Again I apologize for my post being formatted incorrectly.

This post has been edited by jjhaag: 31 Oct, 2007 - 10:47 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:48PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month