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, 21.06.2019 23:30
Me2540 week 5 assignment what do i want to know?
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Write a full class definition for a class named player , and containing the following members: a data member name of type string .a data member score of type int .a member function called setname that accepts a parameter and assigns it to name . the function returns no value.a member function called setscore that accepts a parameter and assigns it to score . the function returns no value.a member function called getname that accepts no parameters and returns the value of name .a member function called getscore that accepts no parameters and returns the value of score .this is what i have, aparently this is wrong: class player{private: string name; int score; public: void player: : setname (string n){name =n; }void player: : setscore (int s){score = s; }string player: : getname (){return name; }int player: : getscore (){return score; }};
Answers: 2
question
Computers and Technology, 22.06.2019 22:30
I'll mark brainliest if answered right! with which feature or menu option of a word processing program can you make an image like this? you can get this image using the option of a word processing program.
Answers: 1
question
Computers and Technology, 23.06.2019 00:00
Donna and her team of five have invented a new gadget for the science exhibition in their college. which intellectual property right will protect their invention?
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
Questions on the website: 13722362