Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need help for these 3 questions

  1. Nov 26, 2006 #1
    Hi guys,

    I'm stucked at these 2 questions from past years exam paper. Can someone advise me how to do it?
    Q(1) Write a C program,marks that writes student marks to a newly created file. The program expects a file name to be passed on the command line and iis invoked like this: marks student.txt

    (part 1) Declare three arrays, firstname, lastname and stdmark that stores the student first name, last name and examination mark (0-100) respectively. Assume that there are 5 students. But the program must be easily changed to cater to more students.

    Initialise the arrays with sample name strings and the following marks: 47, 73,27,65,68

    (part 2) A check for the command line arguments to ensure that the student file is specified. If not, the error message, "usage: marks infile", should be printed, and the program exits.

    (part 3) The file must be created successfully,. If not, the program exits.

    (part 4) A loop to write each students's name and mark in the output file.

    (part 5) Any other code for successfult processing of the file.
    Last edited: Nov 26, 2006
  2. jcsd
  3. Nov 26, 2006 #2

    Using only the switch statement, write C code for the integer function days(month).

    The argument month is an integer in the range 1 to 12 (1 = January, 2 = February,....) The function retuens an integer value representing the number of days in that month. It returns 0 when month is invaild. Assume that the function will only be used this year.

    You should write compact code.
    Thirty days hath September,
    April, June, and November;
    All the rest have thirty-one,
    Excepting February alone,
    And it has twenty-eight days time,
    But in leap years, February has twenty-nine

    Write a more efficient version of days(month), this time without using the swicth statemnet
  4. Nov 26, 2006 #3
    Show your code, tell us what you're having difficulty with, and ask specific questions. I'm not writing the code for you.

    Edit : Here's a start.

    For question 1. It's hard to realise what you could be having difficulty with... all you have to do is translate the question into code. If it's difficulty with accepting the command line invocation. That's what this declaration of main is for.
    Code (Text):
    int main (int argc, char *argv[])
    Where argc is the number of command line arguments that exist, and argv is an array of strings containing all of those arguments, the first one being the actual location of the executable by default. Just post your code so we can see where the difficulty lies.

    For question 2. Use an array of integers. Return the appropriate item from the array based on the input. It sounds almost too easy, I'm wondering if he/she expects something more advanced.
    Last edited: Nov 26, 2006
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Need help for these 3 questions
  1. Python 3 question (Replies: 4)