Pendant Publishing edits multi-volume manuscripts for many authors. For each vol
ID: 3865494 • Letter: P
Question
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design a program that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Pseudocode and flowchart required
please dont use any other languages besides c
Explanation / Answer
#include<iostream>
#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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.