How to make this run? // Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input // file and prints the information to the user's screen. // Input: flowers.dat. // Output: Names of flowers and the words sun or shade. #include #include #include using namespace std; int main() { // Declare variables here string flowerName, growingNeed; // Open input file ifstream fin;//create file object fin.open("flowers.dat");//open the file with its name int line = 0; // Write while loop that reads records from file. cout<<"Flower Need\n"; while(!fin.eof()){//repeat while end of the file //one line contarins name and next contarins its need if(line%2==0){ fin>>flowerName;//store flowerName cout<>growingNeed;//read need either sun or shade cout<

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
How to make this run?
// Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input 
// file and prints the information to the user's screen. 
// Input: flowers.dat. 
// Output: Names of flowers and the words sun or shade. 
#include <fstream> 
#include <iostream>
#include <string> 
using namespace std; 
int main() { 
    // Declare variables here
    string flowerName, growingNeed;
    // Open input file 
    ifstream fin;//create file object 
    fin.open("flowers.dat");//open the file with its name 
    int line = 0;
    // Write while loop that reads records from file. 
    cout<<"Flower           Need\n";
    while(!fin.eof()){//repeat while end of the file
    //one line contarins name and next contarins its need 
        if(line%2==0){
            fin>>flowerName;//store flowerName
            cout<<flowerName<<"          ";//print flowe name 
            line++;//increment line no 
        }
        else{//if odd line no, then its a need linw 
            fin>>growingNeed;//read need either sun or shade 
            cout<<growingNeed<<endl;//print need and move to next line 
            line++;//increment line no 
        }//end else part 
    }//end while 
    fin.close(); //close file object 
    return 0;
} // End of main function
 
flowers.dat
Astilbe
Shade
Marigold
Sun
Begonia
Sun
Primrose
Shade
Cosmos
Sun
Dahlia
Sun
Geranium 
Sun
Foxglove
Shade
Trillium
Shade
Pansy
Sun
Petunia
Sun
Daisy
Sun
Aster
Sun
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT