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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 10:00, serenityharmon1
Hey i just logged on and one of the moderators deleted a bunch of my answers to questions, even though the answers were right and the people it doesn't make sense but if anyone wants to talk about anything just message me lol (this is super random lol)
Answers: 1
image
Computers and Technology, 24.06.2019 02:00, ishmael9332
How are we able to create photographs differently than 100 years ago? explain your answer in relation to your photograph you selected.
Answers: 1
image
Computers and Technology, 24.06.2019 14:30, yeet74
Ahousehold consists of a married couple and their twin five-year old daughters. the couples children had no income and lived with their parents all of last year. how many exemptions can the couple claim on last years tax return or they file with the “ married filing jointly “ status? a. 4 b. 5 c. 3 d. 2
Answers: 1
image
Computers and Technology, 24.06.2019 21:00, genyjoannerubiera
When replacing a thermostat or water pump, coolant drained from the cooling system should be
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 in other subjects: