Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming Question 1: You need to store student IDs and their corresponding marks. You decide to store them in two arrays of 10 elements:

C programming

Question 1:

You need to store student IDs and their corresponding marks. You decide to store them in two arrays of 10 elements:

studID: an array of 10 studentID strings. Each studentID is a string with 7 characters (6 numbers plus the '\0').

marks: an array of integers which will store the mark associated with each studentId.

Write a program that will prompt a user to enter 10 student IDs and student marks and store these values into the arrays.

Write a function called printMarks() which given an array of studentIDs and an array of marks (and any other arguments you may need), prints out both the studentId and the corresponding mark

Update the main() function to call printMarks(). When you test the program, you should get output similar to this: ./student_marks_soln Enter student ID and student mark: 120000 99 Enter student ID and student mark: 120001 95 ... /repeating prompt 10 times Student Marks: ------------------ 120000: 99 120001: 95 ..../ printing out rest of array

Question 2

Write an update function to allow a user to update a student mark. This function should take in two parameters (it can take in more parameters, but must take in at least these two):

ID - a studentId

val - the new mark for that student

This function will iterate through the studId array searching for an element which matches ID. If a match is found, then the corresponding position in the marks array will be set to val and the position where the match was found will be returned. If ID is not found, -1 is returned. Hints:

Remember that when comparing strings, you need to use the strcmp function. See the names.c example from this weeks workshop to see how to use it.

Once you have implemented the update function, add a loop in main() after the first call to printMarks(). This loop should prompt the user if they would like to update a mark. If the user types 'y' then the program should prompt for the student id and new mark and call If the user types 'n', the program should return. (extension: handle the case of when the user types something other than 'y' or 'n' ).

One warning on scanf. When reading a string, scanf will leave the ' ' (newline) character on the input. If you read another string, then that causes no problems as scanf will read past 'white space' (including ' ', tabs, etc) until it gets to a character and read from there. BUT if you read a character instead of a string next, then scanf will read the ' ' as the next character! To avoid this, if you are reading a character after reading a string, use: scanf(" %c", &mychar); Note the extra space in front of the %c. That will cause scanf to skip the ' ' and read the next character entered.

An example run is given here: ./student_marks_soln Enter student ID and student mark: 120000 99 Enter student ID and student mark: 120001 95 ... /repeating prompt 10 times Student Marks: ------------------ 120000: 99 120001: 95 ..../ printing out rest of array Do you want to update a mark? (y or n): y

Enter student ID and new mark: 120000 100

Student Marks: ------------------ 120000: 100 120001: 95 ..../ printing out rest of array

Do you want to update a mark? (y or n): y

Enter student ID and new mark: 122222 100

Student not found! No update. Do you want to update a mark? (y or n): n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions

Question

What is spinal Multiple Sclerosis?

Answered: 1 week ago