Question

In: Computer Science

Write a C program that creates a database of plant height samples. In this scenario a...

Write a C program that creates a database of plant height samples. In this scenario a researcher enters a name of a group/type of plants, and heights for each plant in the group/type Use input will be stored in a database file, which should be a file called database.csv and should be in the following formatPlant1, number_of_samples, sample1, sample2, sample3 ...Plant2, number_of_samples, sample1, sample2, sample3 ...Plant3, number_of_samples, sample1, sample2, sample3 ...Lines starts with the name of a plant type, then an integer indicating the number of following samples. Each sample represents the height of a plant.In your program you should declare a function “input_sample_set” that prompts the user to input plant name and sample count. In this function dynamically allocate memory an array of ints for each plant sample and read in each sample value. Append the data to the database file. Prompt the user “y” or “n” to continuously re-run “input_sample_set” if y is entered. Make sure you deallocate memory after each run of “input_sample_set” to avoid memory leaks.

Solutions

Expert Solution

C program to create a database of plant height samples.

#include<stdio.h>

#include<conio.h>

Struct plant_sample

{

char Group_name[15];

int n;

int* sample_height;   

}

Main()

{                

Struct plant_sample p;

           do

                  {

Printf(“\n enter plant group name: \t”);

gets(p.Group_name);

Printf(“\n Enter howmany samples available: \t”);

Scanf(“%d”,&p.n);

Input_sample_set(p.n);

Fp= fopen(("database.csv", "w+");

// specify the path where you want to store the file

if (fp == NULL)

    {

        fprintf(stderr, "\nError open file\n");

        exit (1);

    }

  fwrite (&p, sizeof(struct person), 1, fp);

printf(“\n do you want to continue (enter y or n):”);

ch=getch();

      }while(ch==’y’|| ‘Y’);

}

Void Input_sample_set(int n)

{

    ptr = (int*) malloc(n * sizeof(int));

// if memory cannot be allocated

if(ptr == NULL)

{

printf("Error! memory not allocated.");

exit(0);

}

printf("Enter sample height: ");

    for(i = 0; i < n; ++i)

        {

Printf(“sample %d”,i+1)

scanf("%d", ptr + i);

        }

   // deallocating the memory

    free(ptr);

}

                                                   


Related Solutions

Write a program (in C, or Java, or C++, or C#) that creates three new threads...
Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this: Thread 1 - iteration no. 1 Thread 2 - iteration no. 1 Thread 3 - iteration no. 1 Thread 1 - iteration no. 2 Thread 2 - iteration no. 2...
Write a C program that creates a toy scheduler for the child processes in part A....
Write a C program that creates a toy scheduler for the child processes in part A. This program takes as input the number of processes, and all of the PIDs that are being echoed. HINT: Look up redirecting echo output. The program will schedule the ”processes” (note that these are not true processes, this is a toy system. You are effectively only scheduling echo statements). The result of the scheduler will be to echo the PID and current system time...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
Write a C program that creates and prints out a linked list of strings. • Define...
Write a C program that creates and prints out a linked list of strings. • Define your link structure so that every node can store a string of up to 255 characters. • Implement the function insert_dictionary_order that receives a word (of type char*) and inserts is into the right position. • Implement the print_list function that prints the list. • In the main function, prompt the user to enter strings (strings are separated by white-spaces, such as space character,...
Write a C program that creates 5 threads sends the thread index as an argument to...
Write a C program that creates 5 threads sends the thread index as an argument to the thread execution procedure/function. Also, the main process/thread joins the newly created threads sequentially one after the other. From the thread procedure print “I am a thread and my index is “ [print the correct index number]. From the main thread after the join print “I am the main thread and just completed joining thread index “ [print the correct index].
Write a C++ program that creates a base class called Vehicle that includes two pieces of...
Write a C++ program that creates a base class called Vehicle that includes two pieces of information as data members, namely: wheels (type int) weight (type float) Program requirements (Vehicle class): Provide set and a get member functions for each data member. Your class should have a constructor with two parameters (one for each data member) and it must use the set member functions to initialize the two data members. Provide a pure virtual member function by the name displayData()...
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes...
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes should start on opposite ends of the screen and then move toward each other. When they meet in the middle of the screen, each shape reverses course and moves toward the edge of the screen. The two shapes keep oscillating and bouncing off of each other in the middle of the screen. The program terminates when the shapes meet each other in the middle...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT