Question

In c programming

Part A: Writing into a Sequential File Write a C program called Lab5A.c to prompt the user and store 5 student records into a file called stdInfo.txt. This stdInfo.txt file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017 30 jim smith 78.2 2018 The skeleton code is given below for your convenience. Use the 3 functions specified to perform the input, printing and saving the records to the file # include <stdio.h> struct student f char firstname [40] char lastname [40]; int id; float GPA; int year; typedef struct student Student; /* Input the student data interactively from the keyboard */ void InputstdRecord (Student *stdList); /* Display the contents of Student records from the list */ void PrintStdList (const Student *StdList); /* Save the student records from the list to the newly created text file specified by FileName */ void SaveStdList (const Student *StdList, const char *FileName); int main() i Student StdList[5] InputStdRecord(StdList); PrintstdList (StdList); SaveStdList (StdList, stdInfo.txt); return 0;.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Lab5A.c

#include<stdio.h>

struct student{

char firstname[40];

char lastname[40];

int id;

float GPA;

int year;

};

typedef struct student Student;

void InputStdRecord(Student *StdList);

void PrintStdList(const Student *StdList);

void SaveStdList(const Student *StdList, const char *FileName);

int main(){

Student StdList[5];

InputStdRecord(StdList);

PrintStdList(StdList);

SaveStdList(StdList, "stdInfo.txt");

return 0;

}

void InputStdRecord(Student *StdList){

int i=0;

for(i=0; i<4; i++){

printf("\nEnter Student %d details: \n", i+1);

printf("ID: ");

scanf("%d", &StdList[i].id);

printf("Firstname: ");

scanf("%s", StdList[i].firstname);

printf("Lastname: ");

scanf("%s", StdList[i].lastname);

printf("GPA: ");

scanf("%f", &StdList[i].GPA);

printf("Year: ");

scanf("%d", &StdList[i].year);

}

}

void PrintStdList(const Student *StdList){

printf("\nID FIRSTNAME LASTNAME GPA YEAR\n");

int i;

for(i=0; i<4; i++){

printf("%d %s %s %.1f %d\n", StdList[i].id, StdList[i].firstname, StdList[i].lastname, StdList[i].GPA, StdList[i].year);

}

}

void SaveStdList(const Student *StdList, const char *FileName){

FILE *fp;

fp = fopen(FileName, "w");

fprintf(fp, "ID FIRSTNAME LASTNAME GPA YEAR\n");

int i;

for(i=0; i<4; i++){

fprintf(fp, "%d %s %s %.1f %d\n", StdList[i].id, StdList[i].firstname, StdList[i].lastname, StdList[i].GPA, StdList[i].year);

}

fclose(fp);

}

Lab5B.c

#include<stdio.h>

struct student{

char firstname[40];

char lastname[40];

int id;

float GPA;

int year;

};

typedef struct student Student;

void ReadStdRecords(Student *StdList, const char *FileName);

void PrintStdList(const Student *StdList);

void wordCap(char *word);

void SaveStdList(const Student *StdList, const char *FileName);

int main(){

Student StdList[5];

ReadStdRecords(StdList, "stdInfo.txt");

PrintStdList(StdList);

SaveStdList(StdList, "stdInfo.txt");

return 0;

}

void ReadStdRecords(Student *StdList, const char *FileName){

FILE *fp;

fp = fopen(FileName, "r");

int i=0;

//for skipping first line

fscanf(fp, "%[^\n]s", StdList[0].firstname);

for(i=0; i<5; i++){

fscanf(fp, "%d %s %s %f %d", &StdList[i].id, StdList[i].firstname, StdList[i].lastname, &StdList[i].GPA, &StdList[i].year);

wordCap(StdList[i].firstname);

wordCap(StdList[i].lastname);

}

fclose(fp);

}

void PrintStdList(const Student *StdList){

printf("\nID FIRSTNAME LASTNAME GPA YEAR\n");

int i;

for(i=0; i<4; i++){

printf("%d %s %s %.1f %d\n", StdList[i].id, StdList[i].firstname, StdList[i].lastname, StdList[i].GPA, StdList[i].year);

}

}

void wordCap(char *word){

int i=0;

while(word[i]!='\0'){

if(word[i]>='a' && word[i]<='z')

word[i] = word[i]-32;

i++;

}

}

void SaveStdList(const Student *StdList, const char *FileName){

FILE *fp;

fp = fopen(FileName, "w");

fprintf(fp, "ID FIRSTNAME LASTNAME GPA YEAR\n");

int i;

for(i=0; i<4; i++){

fprintf(fp, "%d %s %s %.1f %d\n", StdList[i].id, StdList[i].firstname, StdList[i].lastname, StdList[i].GPA, StdList[i].year);

}

fclose(fp);

}

Add a comment
Know the answer?
Add Answer to:
In c programming . Part A: Writing into a Sequential File Write a C program called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • Using the program segment and sample txt file below, write a program that contains a linked...

    Using the program segment and sample txt file below, write a program that contains a linked list of students. The program should allow the user to: 1. initialize list of students 2. add additional student to front of list 3. add additional student to rear of list 4. delete student 5. sort students alphabetically 6. sort students by idNum 7. show number of students in list 8. print students 9. quit program XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The program should be divided into the...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • Am Specification For this assignment, you will write a multi-file C program to define, implement ...

    Must be written and C, and compile with MinGW. Thank you! am Specification For this assignment, you will write a multi-file C program to define, implement and use a dynamic linked lists. Please refer to Lab 07 for the definition of a basic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list of nodes to implement a suit of functions which can be used to create and maintain...

  • Please provide the full code...the skeleton is down below: Note: Each file must contain an int...

    Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...

  • need this in c programming and you can edit the code below. also give me screenshot...

    need this in c programming and you can edit the code below. also give me screenshot of the output #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define LINE_SIZE 1024 void my_error(char *s) { fprintf(stderr, "Error: %s\n", s); perror("errno"); exit(-1); } // This funciton prints lines (in a file) that contain string s. // assume all lines has at most (LINE_SIZE - 2) ASCII characters. // // Functions that may be called in this function: // fopen(), fclose(), fgets(), fputs(),...

  • Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters...

    Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT