CENGAGE MINDTAP Opening Files and Performing File Input in C++ |Opening Files and Performing File Input Summary In this lab, you open a file and read input from that file in a prewritten C++ program....


My while loop needs help. This is what I have while(!fin.eof()). Something else is expected. Please advise.


CENGAGE MINDTAP<br>Opening Files and Performing File Input in C++<br>|Opening Files and Performing File Input<br>Summary<br>In this lab, you open a file and read input from that file in a<br>prewritten C++ program. The program should read and print the<br>names of flowers and whether they are grown in shade or sun. The<br>data is stored in the input file named flowers.dat.<br>Instructions<br>1. Ensure the source code file named Flowers.cpp is open in the<br>code editor.<br>2. Declare the variables you will need.<br>3. Write the C++ statements that will open the input file<br>flowers.dat for reading.<br>4. Write a while loop to read the input until EOF is reached.<br>5. In the body of the loop, print the name of each flower and<br>where it can be grown (sun or shade).<br>6. Execute the program by clicking the Run button at the bottom<br>of the screen.<br>

Extracted text: CENGAGE MINDTAP Opening Files and Performing File Input in C++ |Opening Files and Performing File Input Summary In this lab, you open a file and read input from that file in a prewritten C++ program. The program should read and print the names of flowers and whether they are grown in shade or sun. The data is stored in the input file named flowers.dat. Instructions 1. Ensure the source code file named Flowers.cpp is open in the code editor. 2. Declare the variables you will need. 3. Write the C++ statements that will open the input file flowers.dat for reading. 4. Write a while loop to read the input until EOF is reached. 5. In the body of the loop, print the name of each flower and where it can be grown (sun or shade). 6. Execute the program by clicking the Run button at the bottom of the screen.
Flowers.cpp<br>flowers.dat<br>+<br>from an input<br>2 // file and prints the information to the user's screen.<br>3 // Input: flowers.dat.<br>4 |/ Output: Names of flowers and the words sun or shade.<br>6 #include <fstream><br>7 #include <iostream><br>8 #include <string><br>9 using namespace std;<br>10 int main()<br>11 {<br>12<br>// Declare variables here<br>13<br>14<br>string flowerName, growsIn;<br>15<br>// Open input file<br>ifstream fin;<br>16<br>17<br>18<br>19<br>// Open the file<br>fin.open(> flowerName; fin >> growsIn; 30 31 32 33 34 35 36 // Print flower name using the following format //cout < var=""><« "="" 37="" 38="" grows="" in="" the="" "="">< var2="">< endl;="" cout="">< flowername="">< "="" }="" 39="" grows="" in="" the="" "="">< growsin="" «="" endl;="" 40="" 41="" fin.close();="" 42="" return="" 0;="" 43="" }="" end="" of="" main="" function="" 44="" "/="">
Extracted text: Flowers.cpp flowers.dat + from an input 2 // file and prints the information to the user's screen. 3 // Input: flowers.dat. 4 |/ Output: Names of flowers and the words sun or shade. 6 #include 7 #include 8 #include 9 using namespace std; 10 int main() 11 { 12 // Declare variables here 13 14 string flowerName, growsIn; 15 // Open input file ifstream fin; 16 17 18 19 // Open the file fin.open("flowers.dat"); 20 21 |22 |23 //Check if(!fin) { 24 25 26 27 //Display file not open 28 cout<"\n_error: unable="" to="" open="" the="" file="" flowers.dat.";="" 29="" return="" 1;="" }="" write="" while="" loop="" that="" reads="" records="" from="" file.="" while(!fin.eof(o)="" {="" fin="">> flowerName; fin >> growsIn; 30 31 32 33 34 35 36 // Print flower name using the following format //cout < var=""><« "="" 37="" 38="" grows="" in="" the="" "="">< var2="">< endl;="" cout="">< flowername="">< "="" }="" 39="" grows="" in="" the="" "="">< growsin « endl; 40 41 fin.close(); 42 return 0; 43 } // end of main function 44 growsin="" «="" endl;="" 40="" 41="" fin.close();="" 42="" return="" 0;="" 43="" }="" end="" of="" main="" function="">
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here