subject
Computers and Technology, 21.02.2020 00:01 245cat

File input: strings and numbers

Use cin to ask the user the name of the file. Open the file the user named. Read in two strings (a movie title and a movie snack) and an integer (year the movie was released) from the file. Close the file and print the two string variables. Print the year movie reaches its 100th anniversary.

Note: There will be a hidden test that will read from a different file having the same format as the file linked above but with different content.

Sample Output:

What is the name of the file?
movieinfo. txt
Movie title: Back to the Future
The movie will be 100 years old in 2085.
Movie snack: popcorn
-Now-

Below is my linux command line code (.cpp) and I hard-coded the filename in to my open command. Instead, i want to provide the variable that I typed the name into. I don’t want to hardcode it. I also want it to call on the filename as question described above. Help?

My code:

#include
#include
#include
using namespace std;

int main()
{
string movie_name, movie_snack, mov_snk;
int year, yr;

ifstream dataIn;

dataIn. open("~/movieinfo. txt");

getline(dataIn, movie_name, '\n');
dataIn >> yr >> mov_snk;
year = yr;
movie_snack = mov_snk;

dataIn. close();

cout << "What is the name of the file?" << endl;
cout << "Movie title: " << movie_name << endl;
cout << "The movie will be 100 years old in " << year + 100 << "." << endl;
cout << "Movie snack: " << movie_snack << endl;

return 0;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 01:40
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
Another name for addicting games.com
Answers: 1
question
Computers and Technology, 23.06.2019 23:30
Worth 50 points answer them bc i am not sure if i am wrong
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
When writing a business letter, how many times can you use the same merge field in a document? once once, unless using the address block feature unlimited it will depend on the type of document you choose
Answers: 1
You know the right answer?
File input: strings and numbers

Use cin to ask the user the name of the file. Open the f...
Questions