Write a function, ReadFile(), that reads the content of the provided text file “numbers.txt” (see Appendix A) and stores it in an array. The function receives as parameter a pointer to a character array where the content of the text file should be stored. The number of lines that was read from the text file must be returned to the calling statement.
Question 1.1
Write a function, ReadFile(), that reads the content
of the provided text file “numbers.txt” (see
Appendix A) and stores it in an array. The function
receives as parameter a pointer to a character
array where the content of the text file should be
stored. The number of lines that was read from the
text file must be returned to the calling statement.
Question 1.2
Write a function, analyseStNumber(), which
receives a number as parameter and determines
whether the number is a valid student number or
not. Use the following validity test to determine the
validity of a student number:
Student number: 20570856
sum = (2*8)+(0*7)+(5*6)+(7*5)+(0*4)+(8*3)+(5*2)+(6*1)
result = sum%11
If the result equals 0, the number is a valid student
number; if the result is not equal to 0, the number
is an invalid student number.
The function MUST use a loop to analyse the
number by looking at each individual digit in the
number.
The function returns a 1 (valid) or 0 (invalid) to the
calling statement.
Hint: Repeatedly use integer division (/) with 10
and the remainder after integer division (%) with 10
to isolate the individual digits of the number
Question 1.3
Write a function, WriteFile(), which receives a
student number and status of the student number
as arguments.
If the student number is valid, i.e. status = 1, the
number must be written to an output file,
ValidNumbers.txt. If the student number is invalid,
the number must be written to an output file,
InvalidNumbers.txt (see Appendix A).
The number and status are displayed on the screen
in both cases.
The function returns no value to the calling
statement.
Question 1.4
The above functions (ReadFile(),
analyseStNumber(), and WriteFile()) must now be
implemented in the main program (main()) in the
following order with a fitting message as in
Figure 3:
1. Create an array of type integer and make
provision for a maximum of 100 elements.
2. Read the contents of the text file “numbers.txt”
to the array with ReadFile().
3. Call the analyseStNumber() function to test
each of the numbers in the array for validity.
4. Call the WriteFile() function to write each of the
numbers to the correct output file.



Trending now
This is a popular solution!
Step by step
Solved in 2 steps









