File input: strings and numbers
Use cin to ask the user the name of the file. Open the f...
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;
}
Answers: 3
Computers and Technology, 21.06.2019 22:10
Is the following an example of social media viral marketing? indicate your response by selecting yes or no. when you sign onto your favorite social networking website, you get messages from friends who have seen a television show they thought was a "must see! "
Answers: 1
Computers and Technology, 22.06.2019 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
Computers and Technology, 23.06.2019 13:30
Jace needs to answer a question on square roots to win a quiz. how can he use a spreadsheet to find the square root of 786? a. use the functions round and count b. create a table and chart c. use the function sqrt d. use the function now
Answers: 3
Computers and Technology, 23.06.2019 16:00
What is the biggest difference between section breaks and regular page breaks? section breaks are more difficult to add than page breaks. section breaks make it easier for you to view the document as an outline. section breaks allow you to have areas of the document with different formatting. section breaks are smaller than regular page breaks.
Answers: 2
Biology, 11.05.2021 22:30
Spanish, 11.05.2021 22:30
Mathematics, 11.05.2021 22:30
History, 11.05.2021 22:30
Business, 11.05.2021 22:30
Biology, 11.05.2021 22:30
English, 11.05.2021 22:30
Social Studies, 11.05.2021 22:30
Mathematics, 11.05.2021 22:30