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<
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<
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 1PE
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
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT