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, 22.06.2019 07:00
Our primary purpouse as electricians is to do wich of the following core concepts? a: install electrical components in a way they can be upgraded b: install electrical equiptment in a way that reduces heat c: install electrical systems in a safe manner d: only b and c
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Who needs to approve a change before it is initiated? (select two.) -change board -client or end user -ceo -personnel manager -project manager
Answers: 1
question
Computers and Technology, 23.06.2019 14:00
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
question
Computers and Technology, 25.06.2019 05:30
Radar devices are used by law enforcement to be sure that individuals are driving safely. they tell the officer how fast the vehicle is traveling at that specific moment in time. the radar device determines the vehicle's a. instantaneous speed. b. acceleration. c. maximum velocity. d. average speed.
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
question
Mathematics, 26.09.2019 04:10
question
Mathematics, 26.09.2019 04:10
Questions on the website: 13722363