C How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
C How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
8th Edition
ISBN: 9780134227023
Author: Paul J. Deitel; Harvey Deitel
Publisher: PEARSON
Question
Book Icon
Chapter 7, Problem 7.33MD
Program Plan Intro

Program Plan:

  • Declare prototype for three functions building_CF, car_CF and bicycle_CF.
  • Inside main function,
    • Declare array of function f to point to three functions building_CF, car_CF and bicycle_CF.
    • Declare an integer variable choice to store the user’s choice
    • Use while loop to repeatedly take user’s choice and call different function using array of function.
  • Define function building_CF. Inside this function ask from user for various parameters that can contribute to CO2 emission. Based on value of these paramters and emission factor calculate the carbon foot print for building.
  • Similar as above define function car_CF and bicycle_CF. The CO2 emission of car will be based on type of fuel used in it and for bicyle CO2 emission will depend on the distance travelled.

Summary Introduction: The program uses CO2 emission factors of various fuels used to calculate the carbon footprint for any building, car or bicycle. The program defines three functions for each type of carbon footprint calculation and calls them using array of function.

Program Description:The program prompts the user to enter the type of carbon footprint to calculate and then based on his/her choice uses the array of function to calculate the carbon footprint.

Blurred answer
Students have asked these similar questions
Using C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function.  You can use your own variable names for the parameters.
Is that right?For functions that are flexibly bound, you need pointers or references.
Full source code with a comment in the C program only  Questions (CarbonFootprint Calculator: Arrays of Function Pointers) Using arrays of function pointers, as you learned in this chapter, you can specify a set of functions that are called with the same types of arguments and return the same type of data. Governments and companies worldwide are becoming increasingly concerned with carbon footprints (annual releases of carbon dioxide into the atmosphere) from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. Create three functions that help calculate the carbon footprint of a building, a car and a bicycle, respectively. Each function should input appropriate data from the user then calculate and display the carbon footprint. (Check out a few websites that explain how to calculate carbon footprints.) Each function should receive no parameters and return…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr