Question

Opening Files and Performing File Input in C++

Opening Files and Performing File Input 1 V/ Flowers.cpp This program reads nanes of flowers and whether they are grown in sh

Opening Files and Performing File Input Flowers.cpp 4 /1 Output of flowers and the words sun or 6 | #include <fstream> 7| #in

7 MindTap- Cengage Learning Mozilla Firefox O https//ng.cengage.com/sta ?deploymentid-57536124351246531932978308e1SBN 9781 CE

static/nb/ui/evo/index.htmi?deploymentld-5753612435124653193297830&telSBN-9781337274 Performing File Input in C++ les and Flo

Foxglove grows in the Shade Trillium grows in the Shade Pansy grows in the Sun Petunia grows in the Sun Daisy grows in the Su

Opening Files and Performing File Input 1 V/ Flowers.cpp This program reads nanes of flowers and whether they are grown in shade or sun from an input 2 file and prints the information to the user's screen. 3 Input: flowers.dat 41 Output: Names of flowers and the words sun or shade 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. 6: #include «fstream» 7 #include 8 #include 9 using namespace std 10 int main() 2 Declare variables Instructions Open input fil 1. Ensure the source code file named Flowers.cpp is open in the code editor. 2. Declare the variables vou will need 3. Write the C++ statements that will open fin flowerNane the input file flowers.dat for reading 4. Write a while loop to read the input until FOF is reacherd
Opening Files and Performing File Input Flowers.cpp 4 /1 Output of flowers and the words sun or 6 | #include 7| #include 3. Write the C++ statements that will open Prinrose 8 Shade 9 Cosmos 10 Sun 11 Dahlia 12 Sun 3 Geranium 14 Sun Is FoxgLove the input file flowers.dat for reading. 4. Write a whtle 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. Trilliun 8 Shade 19 Pansy Sun Grading When you have completed your program click the Submit button to record your score l Petunia O Type here to search
static/nb/ui/evo/index.htmi?deploymentld-5753612435124653193297830&telSBN-9781337274 Performing File Input in C++ les and Flowers.cpp flowers.dat 6 Sun 7 Prinrose 8 Shade 9 Cosmos 10 Sun 11 Dahlia 12 Sun 13 Geranium 14 Sun 15 Foxglove 16 Shade 17 Trilltum 18 Shade 19 Pansy 20 Sun 21 Petunta g File Input open in the code editor iables you will need tatements that will open owers.dat for reading. loop to read the input ched the loop, print the name and where it can be shade). ogram by clicking the Run bottom of the screen. Sun 23 Daisy Aster Sun ompleted your program button to record your earch 4o
Foxglove grows in the Shade Trillium grows in the Shade Pansy grows in the Sun Petunia grows in the Sun Daisy grows in the Sun Aster grows in the Sun ull Expected Output Astilbe grows in the Shade Marigold grows in the Sun Begonia grows in the Sun prinrose grows in the Shade cosmos grows in the sun Dahlia grows in the Sun Geranium grows in the Sun Foxglove grows in the Shade Trilliun grows in the Shade Pansy grows in the Sun Petunia grows in the Sun Daisy grows in the Sun Aster grows in the Sun 2 Program utilizes correct code Run checks O Type here to search
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Source Code in C++:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream fin; //creating file object for input
fin.open("flowers.dat"); //opening file
string flower,origin; //to store flower and their origin of growth
while(fin >> flower && fin >> origin) //while file has flower and origin
{
cout << flower << " grows in the " << origin << endl; //output
}
return 0;
}

Input File:

media%2F1a2%2F1a2514e6-e0a7-4c15-b72a-26

Output:

י CAUsersDebit GDocumentsFlowers.exe stilbe grows in the Shade Marigold grows in the Sun Begonia grows in the Sun Primrose

Add a comment
Know the answer?
Add Answer to:
Opening Files and Performing File Input 1 V/ Flowers.cpp This program reads nanes of flowers and ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • How do I complete this problem? * CENGAGE MINDIAP > Terminal Opening Files and Performing FileInput...

    How do I complete this problem? * CENGAGE MINDIAP > Terminal Opening Files and Performing FileInput in C++ 0 Opening Files and Performing File Input Flowers.cpp flowers.dat 1 // Flowers.cpp - This program reads names of flowers and whether they are grown in shade or sun from an input 2 // file and prints the information to the user's screen. 3.// Tnput: flowers.dat. 4 // Output: Names of flowers and the words sun or shade. Summary In this lab, you...

  • I have my assignment printing, but I can find why the flowers is printing null and...

    I have my assignment printing, but I can find why the flowers is printing null and not the type of flower. Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where it can be...

  • I'm working with Java and I have a error message  1 error Error: Could not find or...

    I'm working with Java and I have a error message  1 error Error: Could not find or load main class Flowers. This is the problem: Instructions Make sure the source code file named Flowers.java is open. Declare the variables you will need. Write the Java statements that will open the input file, flowers.dat, for reading. Write a while loop to read the input until EOF is reached. In the body of the loop, print the name of each flower and where...

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type...

    *JAVA File Input/Output Homework* (4 parts) Part 1 1) Open a TEXT editor program 2) Type in 50 words, one word per line, all words of the SAME catagory, max chars per word is 8. Example: 50 words of some names in the periodic table, or Flowers, or cars or.... 3) Save the file as myWordFile.txt Part 2 Write a program the reads the myWordFile.txt 1) Create an array of 'strings' called myWordArray 2) Write code that opens the file...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT