diff --git a/readWriteRecordsToAFile.cpp b/readWriteRecordsToAFile.cpp new file mode 100644 index 0000000..431e4fa --- /dev/null +++ b/readWriteRecordsToAFile.cpp @@ -0,0 +1,113 @@ +/* A C++ program to read and write multiple student details to files, + read them and if required, delete the files aswell */ + +#include //Used for the standard I/O functions ie cin and cout +#include //Used for file manipulation tasks + +using namespace std; + + + +char filename[20]; //A string to store the name of the file globally + +struct student{ // A structure to store student details + char name[20]; + char usn[20]; + int age; +}; + +student studentInput(); // A function prototype for a function that takes student data +void studentDisplay(struct student); // A function prototype for a functon that displays student data +void studentWrite(struct student); // A function prototype for a function that writes data to a file +student studentRead(struct student); // A function prototype for a function that reads data from a file + +int main() +{ + int n; // To store the number of records + char ch; // To store the choice + student *s; + s = new student[10]; // To store the records + cout<<"We will create a file! Give it a name:\n"; + cin>>filename; + // A do while loop to control the exit of the program. + do{ RESTART: + cout<<"************************************************************\n"; + cout<<"Choose what to do with the file "<>ch; + cout<<"\n************************************************************\n"; + + switch(ch) + { + case '1': cout<<"Enter the number of student records to be written.\n"; + cin>>n; + + // A loop to write n number of records + for(int i=0;i>s.name; + cout<<"Enter the student's USN:\n"; + cin>>s.usn; + cout<<"Enter the student's age:\n"; + cin>>s.age; + cout<<"\n************************************************************\n"; + + return s; +} +void studentDisplay(student s) // A function that displays student data +{ + cout<<"*****File Read Sucessfully*****\n\nName: "<