How Do You Write a C Program to Handle Student Marks and File Operations?

  • Thread starter shermaine80
  • Start date
In summary, the first question asks a programmer to write a C program that marks student marks to a new file. The second question asks the programmer to write an integer function that returns the number of days in a given month.
  • #1
shermaine80
30
0
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:
Technology news on Phys.org
  • #2
Q(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
 
  • #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 realize 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:
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:

What kind of help do you need for these 3 questions?

I am looking for assistance with answering three specific questions related to my research or experiment. I may need clarification, guidance, or suggestions on how to approach the questions.

How important is it to get help for these 3 questions?

It is crucial to get help for these questions as they may be critical to the success of my research or experiment. Getting assistance can help me avoid mistakes and ensure the accuracy and validity of my findings.

Who can help me with these 3 questions?

Depending on the nature of the questions, there are various individuals who can provide assistance. This can include colleagues, mentors, advisors, or experts in the field. It is important to seek help from someone knowledgeable and experienced in the relevant subject matter.

What should I do if I am unable to find help for these 3 questions?

If you are unable to find help from colleagues or experts, you can also try reaching out to online forums or communities related to your field of study. You can also consider consulting textbooks, articles, or other resources for guidance on how to approach the questions.

How can getting help for these 3 questions benefit my research or experiment?

Getting help for these questions can lead to a better understanding of the subject matter and improve the quality of your research or experiment. It can also help you identify any potential flaws or limitations in your approach and find more efficient or effective methods of data collection and analysis.

Similar threads

  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Programming and Computer Science
Replies
10
Views
25K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Programming and Computer Science
Replies
6
Views
5K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
3
Views
3K
Back
Top