1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
White raven [17]
3 years ago
5

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 name

s of flowers and whether they are grown in shade or sun. The data is stored in the input file named flowers.dat. Instructions Ensure the source code file named Flowers.cpp is open in the code editor. Declare the variables you will need. Write the C 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 grown (sun or shade). Execute the program by clicking the Run button at the bottom of the screen.
Computers and Technology
1 answer:
Bezzdna [24]3 years ago
5 0

Answer:

#include <stdio.h>

#include <string.h>

void main( )

{

array flowerProp[2];

FILE *fp; // file pointer

char flower[255]; // creating a char array to store data

fp = fopen("flowers.dat","r");

if (fp == NULL){

   printf("File flower.dat does not exist");

   return;

}

// assuming the growing condition is next line to the flower name.

while(fscanf(fp, "%s", flower)!=EOF){

   flowerProp.push(flower);

   if (flowerProp.length == 2){

       printf("%s: %s\n ", flowerProp[0], flowerProp[1]);

       memset(flowerProp, 0,0);

   }

}    

fclose (fp );

}

Explanation:

The algorithm creates a pointer to the memory location to the file starting position, the character size is used to get a string from the file line by line. Then it opens and checks if the file exists.

If the file exists, the while gets the name and growth condition of the flower, saves it to an array, prints the name and condition, and clears the array for the next flower type in the loop.

You might be interested in
Describe how a black and white image could be represented in binary
SIZIF [17.4K]

Answer:

Each pixel in an image is made up of binary numbers. If we say that 1 is black (or on) and 0 is white (or off), then a simple black and white picture can be created using binary. To create the picture, a grid can be set out and the squares coloured (1 – black and 0 – white).

5 0
3 years ago
Read 2 more answers
Tech A states that batteries have different sizing and configuration requirements. Tech B states that this helps them to fit the
Ymorist [56]

Answer:

Both

Explanation:

Batteries come in different sizes and configurations. This is evident in car batteries where third sizes vary from car to car depending on the space and manufacturer's discretion.

Thus, Both technicians are correct.

Cheers

3 0
4 years ago
What is an example of a situation in which you might use the append method? In what ways is the append method limited?
Oksanka [162]
If I had an array of the names of people who just walked in the door. I’d append the name of the person who came in next. To update the array.

The append method needs to be looped through to add multiple inputs
5 0
3 years ago
What is a characteristic of an open software license
Darya [45]

Answer: Something people can change and share. It is usually given the bad name of have a bunch of fake information and bugs. Wikipedia is a good example of an open source website but it is not a program.

Explanation: An open source program is a program where you have free rein to basically do whatever you want to it.

3 0
4 years ago
Nat is defined in rfc ____, which describes methods for connecting private (internal) ip addresses to the internet.
algol13
Describing methods for connecting private (internal) IP addresses to the internet using NAT was defined in RFC 3022. NAT has servers that use port forwarding to send connections from external clients to the Web server on the internal network. NAT is used on routers to hide internet IP address from the internet.



7 0
4 years ago
Other questions:
  • ACCOUNTING
    13·2 answers
  • The purpose of the ________ element is to describe the contents of a table.
    15·1 answer
  • List of programming languages and their typing
    5·2 answers
  • What will the output be from the following program?
    5·1 answer
  • What is the printout (display) of the following program? public class Test { public static void main(String[] args) { int[][] va
    9·1 answer
  • Write a program with a method computeCommission which takes a double that is the salesAmount and returns the commissions for sal
    9·1 answer
  • Write a program that asks for the names of three runners and the time, in minutes (no seconds, etc.), it took each of them to fi
    7·1 answer
  • Digital signatures are as legally acceptable as written signatures.
    12·1 answer
  • Define a function compute gas volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use the
    7·2 answers
  • Write a method named lastIndexOf that accepts an array of integers and an * integer value as its parameters and returns the last
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!