[SOLVED] IT1010 Lab Sheet 7

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab-Sheet-7-fd8aav.zip (239 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (2 votes)

 

Objectives : 

At the end of this class the students will be able to

  • Create a sequential access file to store and retrieve data.
  • Store data into a sequential file.
  • Retrieve data from a sequential file.

Exercise 1

A university needs to maintain a text file to store and retrieve their student’s details such as name, class, year and total marks.

  1. Write a C program to do the following;
  2. Create a file pointer

 

FILE *fPtr;

 

  1. Open the file to write data

 

fPtr = fopen ( “Student.dat”, “w”);

 

  1. Input the data of 5 students from the keyboard and store in the file. Write the data

to the file using

 

fprintf(fPtr, “%s %c %d %d \n”, name, class, year, GPA);

 

  1. Modify the program to open the “Student.dat” file you created above and print the data in a tabular form as shown below in the screen.

 

Name             Class              Year              GPA                                           

Nimal                 1                     1                   3.7

Sunil                  1                     2                   4.0

Kamal                 3                     3                   2.7

Mihiri                 2                     1                   1.7

Mala                  2                     4                   2.1

 

Exercise 2

 

Write another program to read the “Studnet.dat” file and display name and GPA of the students in a given year. The user should be able to input the year from the keyboard.

 

1

  • Lab-Sheet-7-fd8aav.zip