Question

please write this program in C++(Linux). Also write all the explanation of codes, the comment for your code.

Description You are an avid reader and have decided that you would like to keep track of the books that you read. You will define a structure called book_list that will hold 1. a number associated with each book (int) 2. book title (string), 3. author (string), 4. a description of the book (string), 5. a date when the book was read stored in 2 parts - month (int) and year (int) a 6. a rating of the book (int) The number will be generated by the program as each book is entered. The rating should be limited to a number between 1 and 10. It will be a scale the user can use to enter what they thought of the book. The month should be a valid month and the year should be less than the current year and not negative. The program should ask the user for all of the book information, except for the number, until the user enters exit as the book title. After each book is entered, it should be written to an output file called reading list.txt. The file should contain all of the information including the number for each book. Each item of the book should be printed on a new line. Each time the program is restarted, it should open the file to append to the end of the file

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

#include<iostream>
#include<string.h>
#include<fstream>
#include<ctime>
#include<iomanip>
using namespace std;
struct book_list
{
int number,year,month,rating;
string title,author,desc;
}ob;//structure variable
int book_number()
{
//initializing the count variable
int count=0;
string line;//storing the line
ifstream file("reading_list.txt");//opening the file in read mode
while(getline(file,line))//getting the each line from the file and loop terminates when there is no line to count
count++;//increment the line count by 1
file.close();//close the file
return count;//return the count
}
void writedata()
{
fstream file;//opening file
file.open("reading_list.txt",fstream::out|fstream::app);//opening file with open or append mode
file<<ob.number<<endl;//writing the book number to file
file<<ob.title<<endl;//writing book title to file
file<<ob.author<<endl;//writing author to file
file<<ob.desc<<endl;//writing description to file
file<<setfill('0')<<setw(2)<<ob.month<<" "<<setw(4) <<ob.year<<endl;//writing year and month to file
file<<ob.rating<<endl;//writing rating to file
file.close();
}
int main()
{
int n=book_number()/5;//getting the how many book are there in reading list
//divided the book_number()/5 because each record occupies the 5 lines so we get how many book are there
//getting current year
time_t theTime = time(NULL);
struct tm *aTime = localtime(&theTime);
int cyear=aTime->tm_year+1900;

while(true)
{
ob.number=n+1;//generating the book number
cout<<"Enter Book Title:"<<endl;
getline(cin,ob.title);
if(ob.title=="exit")//if book title is exit then quit
{
break;
}

cout<<"Enter Book Author:";
getline(cin,ob.author);

cout<<"Enter Book Description:";
getline(cin,ob.desc);

do{
cout<<"Enter Month:";
cin>>ob.month;
}while(ob.month<1 || ob.month>12);//checking the month
do{
cout<<"Enter year:";
cin>>ob.year;
}while(ob.year<0 ||ob.year>cyear);//checking the year

do{
cout<<"Enter Rating between 1 and 10";
cin>>ob.rating;
}while(ob.rating<1 || ob.rating>10);//checking the rating
cin.ignore();

n++;
cout.flush();
writedata();
}
}

sample input:

CAUserslramarlDesktoplbook.exe EnterBookTitle: wings of fire Enter Book Author:A. P. J. Abdul Kalam Enter Book Description:Ansample out:

reading list.tt - Notepad File Edit Format View Help 1 Les Miserables Victor Hugo Aconvict changes his life 01 2017 wings of

if you have any doubt please comment

Add a comment
Know the answer?
Add Answer to:
please write this program in C++(Linux). Also write all the explanation of codes, the comment for...
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
  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • In Python, write a program that reads a text file that is provided by the user...

    In Python, write a program that reads a text file that is provided by the user - ensure that the file exists before processing it! The file might be in a different directory, so be sure to test you logic - the user will provide the absolute path to the file if it is not in the same directory as the Python script! You should then ask the user for what string to search for in the file. Your program...

  • This will be done using Python in Linux Mint. The program should include a comment block...

    This will be done using Python in Linux Mint. The program should include a comment block at the top with your name, the program number, and the name of the course. (Make sure to have the file that does have the extension .py) How to run the file in Linux Mint?  Open a command prompt (e.g. terminal)  Make sure you are in the directory where your file is saved (e.g. type "cd ~/Desktop" if your file is on...

  • Program Description: (C++). Write a word search program that searches an input data file for a...

    Program Description: (C++). Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of characters in the input data file that are not vowels. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string &word, int &wordCount, int &nonVowelCount) ; void...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • please use C++ write a program to read a textfile containing a list of books. each...

    please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...

  • Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix...

    Netflix Database - PROGRAMMED IN JAVA PLEASE :) In this program, you will build a Netflix movie database using the provided file, netflix.csv. The file contains more than two hundred records of movies and TV programs, with each record consisting a title, a rating, a release year, and a user rated score. There are three classes that you will need to implement: Movie, NetflixHandler, and NetflixApp. Class: Movie Movie - title: String - rating: String - year: int - score:...

  • Can you write with comments please. Thank you. Write a Java Program that asks the user...

    Can you write with comments please. Thank you. Write a Java Program that asks the user to enter the responses on the Console and write the responses to a text file called responses.txt (in the same directory as the program) Write another JAVA prorgram to read responses.txt file and calculate the frequency of each rating in the file and output the number and frequency in two columns (number, frequency) on the Console.

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