please write this program in C++(Linux). Also write all the explanation of codes, the comment for your code.
#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:
sample out:
if you have any doubt please comment
please write this program in C++(Linux). Also write all the explanation of codes, the comment for...
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. •...
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...
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 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 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 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...
Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following tasks based on the Linux Fundamentals lecture. For this lab, take screenshots for all major steps completed to illustrate that each task was successfully completed the same method as would be used for other labs). Tasks: 1. Create a new user named Billy Bob using the command linter face 2. Add Billy Bob to the sudoers group 3. Update and upgrade your Linux distribution...
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.
OPERATING SYSTEM... C , LINUX Modify the mycat.c program to write to stderr the number of bytes that were read from stdin each time. You may use cLion inside VM, or any other text editor of your choice, such as vi or emacs. There is also a neat text editor named Kate available in Ubuntu (you can find it in the menu). In cLion you can open a single.cfile without having to create a whole new project and modify the...
Hi, I need to write a program for linux (putty) and please read carefully (I've asked the same question 3 times because the experts who answered my questions wrote their own carmain1.cpp file. Please leave it where it is and only create car.cpp and car.h files.) Here's carmain1.cpp /* carmain1.cpp * Please don't rewrite this file * I will be using the exact * same file below when grading * */ #include <iostream> #include "car.h" using namespace std; int main()...