Need help with assignment

This is a discussion on Need help with assignment within the C Programming forums, part of the General Programming Boards category; I'm trying to do some assignments my friend used to take when he was in a C class, although I ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Need help with assignment

    I'm trying to do some assignments my friend used to take when he was in a C class, although I am not, I was trying to familiarize myself with the programming language.

    I've learned quite a bit, up to the point where I can implement basic sub functions etc, I even messed around a bit with multidimensional arrays.

    However, I'm at a loss of what this code is suppose to look like and how to perform it.

    When the function, ie, inputFahrs is called, it's expecting 2 parameters, of which I am just not understanding how it would receive.

    If anyone can refresh me or give me some rudimentary examples of what this might look like, in the context of the specifications itself, that would be awesome.

    Thanks in advance!

    (Specifications)

    This program uses arrays and functions to input multiple data items (temperatures) that are each within a certain range and then output some information about them.

    1. The program will input from 1 to 20 (inclusive) Fahrenheit temperatures from the user. You must first ask them to enter the number of temperatures that they will be typing in. If the value entered is not between 1 and 20, you need to display a message informing the user that the value they entered is out of range and make them re-input until they provide an acceptable value.

    2. The Fahrenheit values are doubles and must range between -100.0 and 150.0 (inclusive.) If an out-of-range temperature is entered, you must display a message informing the user as such and have them re-input until an in-range value is entered.

    3. Display all values in ascending order as both Fahrenheit and Celsius values.

    4. Display the average in Fahrenheit and Celsius, followed by the highest and lowest temperatures (in Fahrenheit and Celsius.)

    5. Finally, output the amount of Fahrenheit temperatures (not the actual temperatures, just how many) that fall within the specified gradations.

    Notes/Specifications:
    a) Certain tasks must be put in their own function and each of the functions listed below must be part of your program. Each function needs to handle just its primary task (e.g. no output unless it’s specified). Redundant work and/or doing any of the assigned function’s work elsewhere (e.g. main()) will incur a significant penalty. You may add other functions that do tasks not listed here.

    void inputFahrs(double data[], int numFahrs) – prompts and inputs numFahr values within the specified range (enforced.)

    double fahrToCels (double fahr) – takes in a Fahrenheit temperature and returns the corresponding Celsius value.

    void outputFahrs(double data[], int numFahrs) – outputs a descriptive header followed by all of the Fahrenheits in ascending order, one on a line, alongside the corresponding Celsius value.

    void outputAverage (double data[], int numFahrs) – outputs the average of all the values in the array in Fahrenheit and Celsius.

    void outputHighLows (double data[], int numFahrs) – Outputs the high and low values as both Fahrenheit and Celsius.

    void outputGrads (double data[], int numFahrs) – Outputs how many Fahrenheit values belong to each of the following gradations:

    i. Below 0.0
    ii. Between 0.0 and 32.0 (inclusive)
    iii. Above 32.0 and less than 68.0
    iv. At least 68.0 and less than or equal to 100.0
    v. Above 100.0


    b) Display all floating-point (double) numbers to one decimal place.
    c) All output needs to be right-justified and aligned by the decimal point (see below.)
    d) The first line of your output must be your name, followed by “Assignment 2”.
    e) Use blank lines to separate your output and label each piece of output.
    f) You are expected to use standard style guidelines (e.g. alignment of braces, indention, etc.) as covered in class. Use white space generously within statements where it will be helpful (e.g. on either side of arithmetic operators.) Leave one or two blank lines between each function. Lines of code that run into the margin and/or into the next line will be penalized.


    Sample output:
    CIS 231 - Assignment 2 – Your Name
    Fahr Cels
    ====== ======
    30.0 -1.1
    40.0 4.4
    50.0 10.0
    ====== ======
    Average 40.0 4.4
    High: 50.0 10.0
    Low: 30.0 -1.1

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > void inputFahrs(double data[], int numFahrs) – prompts and inputs numFahr values within the specified range (enforced.)
    Would be called with

    double array[42];
    inputFahrs( array, 42 );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    So, this is implying that I would do this by giving the index and data to the function inputFahr?

    Wouldn't it be simpler to just have this in a loop within the main proc?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    5,857
    Quote Originally Posted by C_Davis View Post
    So, this is implying that I would do this by giving the index and data to the function inputFahr?
    Not precisely. The arguments are the pointer to the first element of the array, and the number of elements in the array.

    Quote Originally Posted by C_Davis View Post
    Wouldn't it be simpler to just have this in a loop within the main proc?
    Depends what you mean by "simpler".

    "Simpler" in your case would mean failing the assignment. If you are happy to fail the assignment, then go for your notion of "simpler".

    In the real world, simple programs (like you have been asked to work on for your assignment) rarely exist. Real-world programs tend to be large, so they get broken down into smaller pieces that are easier to understand i.e. functions. It may seem simpler to put everything into the main() function. But there comes a point where the main() function becomes large enough that it is difficult to understand, and therefore difficult to get right. The reason your assignment is forcing you to break things into functions is so you understand the techniques that will work with building real-world programs that work - albeit using a small and simple example.
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Haha, grumpy you sound like someone I know all to well.

    Thanks for the tip, I've got it moving along now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 08:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21