CSC1300: LAB 8 – arrays

$30.00 $24.00

Concepts Arrays Functions Header files & multiple source files specifications Create a program that will allow the user to enter in the name of 10 elephants and also enter in the amount (in pounds) of food each elephant eats per month. Then, find & print the total and average number of pounds eaten by all…

Rate this product

You’ll get a: zip file solution

 

Categorys:

Description

Rate this product

Concepts

  • Arrays
  • Functions
  • Header files & multiple source files

specifications

Create a program that will allow the user to enter in the name of 10 elephants and also enter in the amount (in pounds) of food each elephant eats per month. Then, find & print the total and average number of pounds eaten by all the elephants. Then, find & print the name and food amount of the elephant that eats the most food.

Implementing a Program in Multiple Files

You will have several functions in this program and you will implement the program in three files:

  • Driver.cpp – this file contains the main function only
  • Functions.cpp – this file contains all the programmer-defined functions
  • Elephant.h – this is your header file which has all the #includes, global constants, and function prototypes.

variables in this assignment

  1. Global constant for the array SIZE, which should be set to 10.
  2. Two floating point variables local to the main function that will hold the food total and food average.
  3. An integer local to the main function representing the index of the elephant that had the largest amount of food consumption.
  4. A character array of size 100, which will hold the name of the elephant zoo.
  5. Local variable in the main function which is an array of 10 floats. This array is going to hold the number of pounds each elephant eats.
  6. Local variable in the main function which is an array of 10 strings. This array is going to hold the name of each elephant at the zoo.

header fileS

This program requires you to write a header file (Elephant.h) Header files allow you to put some code in a separate file in order to speed up compile time, keep your code more organized, and separate interface from implementation. There is an article called “Headers and Includes: Why and How” on cplusplus.com if you would like more information on this topic: http://www.cplusplus.com/forum/articles/10627/

You must always use an include guard for header files so that they are only included in a single program one time. There is an article on include guards on Wikipedia if you would like more information on this topic: https://en.wikipedia.org/wiki/Include_guard.

Sample Include Guard for Elephant.h

#ifndef ELEPHANT_H

#define ELEPHANT_H

//all your code for your header file

#endif

Main Function (in Driver.cpp)

Write a driver program (Driver.cpp) that contains the main function. You should do the following steps in the main function:

  • Asks the user for the name of their zoo and reads in that name to the character array (c-string) that you created.
  • Calls the getElephantData function, sending the elephant food array and the elephant name array to this function.
  • Call the getStats function, sending the elephant food array and the elephant name array to this function. You should also pass three other variables by reference to this function including total, average, and highest index.
  • Print the results to the screen in a nice, readable way including the:
    • elephant zoo name,
    • total amount (in pounds) of food consumed by all the elephants
    • average amount (in pounds) of food consumed by the elephants
    • name and amount (in pounds) of the elephant who eats the most

Functions.cpp (all programmer-defined functions)

The following functions should be included in this file:

getElephantData

Return type: void

Parameters: float array for elephant food amounts, string array for elephant names

Purpose: this function will iterate through each element of the array and allow the user to enter in each of the 10 elephant’s names and the amount of food that elephant eats in one month.

getStats

Return type: void

Parameters:

  • float array for elephant food amounts
  • float (passed by reference) to hold the total
  • float (passed by reference) to hold the average
  • int (passed by reference) to hold the index of the elephant that had the largest amount of food consumed.

Purpose: this function will find the total number of pounds eaten by all the elephants. Then it will find the average number of pounds eaten by the elephants. Then, it will determine the index of the elephant that ate the most.

compiling with header file & multiple source files

g++ Driver.cpp Functions.cpp –o Elephant

sample output

Hello! What is the name of your elephant zoo?

April’s Elegant Elephant Zoo

Enter the name and how many pounds of food each elephant ate last month.

ELEPHANT 1:

NAME – Joyce

FOOD AMOUNT – 4567

ELEPHANT 2:

NAME – Bob Ross

FOOD AMOUNT – 3945.67

ELEPHANT 3:

NAME – Super Scout

FOOD AMOUNT – 2345.99

ELEPHANT 4:

NAME – Sheila

FOOD AMOUNT – 1234.3

ELEPHANT 5:

NAME – Miss Piggy

FOOD AMOUNT – 8564.55

ELEPHANT 6:

NAME – Boss Hog

FOOD AMOUNT – 8321.1

ELEPHANT 7:

NAME – Phil Pooper

FOOD AMOUNT – 3454.3

ELEPHANT 8:

NAME – Scott Smart

FOOD AMOUNT – 6541

ELEPHANT 9:

NAME – Hope

FOOD AMOUNT – 2323.4

ELEPHANT 10:

NAME – Moody Madge

FOOD AMOUNT – 993.1

—————————————————————–

The total amount of food consumed by all 10 elephants at April’s Elegant Elephant Zoo is 42290.4 pounds in one month.

The average amount of food consumed at April’s Elegant Elephant Zoo is 4229.04 pounds.

The elephant who eats the most (8564.55 pounds) is Miss Piggy!!

—————————————————————–

What to Turn In

ZIP & upload the following files to the ilearn submission folder:

  • Driver.cpp
  • Functions.cpp
  • Elephant.h
CSC1300: LAB 8 – arrays
$30.00 $24.00