Answer:
See explaination for the program code
Step-by-step explanation:
The code
#include<fstream>
using namespace std;
//Read data from file and returns number of records
int readFile(string authorName[], string title[], int volumeNo[], int volumeNo1[])
{
//Creates an object of ifstream
ifstream readf;
//Opens the file volume.txt for reading
readf.open ("volume.txt");
//Counter for number of records
int c = 0;
//Loops till end of file
while(!readf.eof())
{
//Reads data and stores in respective array
readf>>authorName[c];
readf>>title[c];
readf>>volumeNo[c];
readf>>volumeNo1[c];
//Increase the record counter
c++;
}//End of while
//Close file
readf.close();
//Returns record counter
return c;
}//End of function
//To display records information
void Display(string authorName[], string title[], int volumeNo[], int volumeNo1[], int len)
{
int counter = 0;
//Displays the file contents
cout<<"\\ The list of multi-volume manuscripts \\";
cout<<("____________________________________________________");
//Loops till end of the length
for(int x = 0; x < len; x++)
{
cout<<"\\ Author Name: "<<authorName[x];
cout<<"\\ Title: "<<title[x];
cout<<"\\ Volume "<<volumeNo[x]<<" of "<<volumeNo1[x]<<endl;
}//End of for loop
//Displays total records available
cout<<"\\ The Records: "<<len;
}//End of function
//Main function
int main()
{
//Creates arrays to store data from file
string authorName[100], title[100];
int volumeNo[100];
int volumeNo1[100];
//To store number of records
int len;
//Call function to read file
len = readFile(authorName, title, volumeNo, volumeNo1);
//Calls function to display
Display(authorName, title, volumeNo, volumeNo1, len);
return 0;
}//End of main
volume.txt file contents
Pyari CPorg 1 2
Mohan C++ 3 4
Sahu Java 6 7
Ram C# 4 2
Sample Run:
The list of multi-volume manuscripts
____________________________________________________
Author Name: Pyari
Title: CPorg
Volume 1 of 2
Author Name: Mohan
Title: C++
Volume 3 of 4
Author Name: Sahu
Title: Java
Volume 6 of 7
Author Name: Ram
Title: C#
Volume 4 of 2
The Records: 4