File named geometry.h

Submit the .cpp and .h source code files on Ecampus.

  1. Create a file named geometry.h that will contain the following functions:
    VolSphere()
    AreaSphere()
    VolCone()
    AreaCone()
    VolCylinder()
    AreaCylinder()
    VolDonut()
    Hint: Donut/Torus volume = 2 * pi * pi * R * r * r

Food items will have these dimension:
Apple - sphere that is 3" diameter
Pizza - cylinder that is 12" diameter and 0.5" thick
Donut - 4" diameter and 2" hole (R=1.5, r=0.5)
Ice Cream Cone - cone is 5" tall with a 2" diameter; it has one scoop of ice cream that's a 2.5" diameter sphere

Create a program named food.cpp that asks the user how many apples, pizzas, donuts, and ice cream cones they will eat. Tell the user the total volume of food they will eat.
Please turn in both the geometry.h file and food.cpp

  1. Write a program called lol.cpp that allows the user to enter a sentence. Then program then searches the sentence for various lolspeak abbreviations and substitutes them with the proper words.
    You should have a function named LOLSpeak that takes your sentence, abbreviation, and translation as parameters and returns the corrected sentence:
    string LOLSpeak(string S, string Abbr, string Translation)
    Make your program work with the three abbreviations below AND at least 7 more of your own (total 10). You may assume that there is a space before and after your abbreviation.
    Search for this Replace it with this
    " u " " you "
    " lol " " laughing out loud "
    " brb " " be right back "
    Note: You cannot use a normal cin statement to input a sentence (it truncates after the first space). Use the getline function:
    String S;
    getline(cin,S);
  // geometry.h #ifndef GEOMETRY_H #define GEOMETRY_H #include const double pi = 3.14159265359; double VolSphere(double radius) { return (4.0 / 3.0) * pi * pow(radius, 3); } double AreaSphere(double radius) { return 4 * pi * pow(radius, 2); } double VolCone(double radius, double height) { return (1.0 / 3.0) * pi * pow(radius, 2) * height; } double AreaCone(double radius, double height) { double slant_height = sqrt(pow(radius, 2) + pow(height, 2)); return pi * radius * (radius + slant_height); } double VolCylinder(double radius, double height) { return pi * pow(radius, 2) * height; } double AreaCylinder(double radius, double height) { return 2 * pi * radius * (radius + height); } double VolDonut(double outer_radius, double inner_radius) { return 2 * pi * pi * outer_radius * inner_radius * inner_radius; } #endif // food.cpp #include #include "geometry.h" int main() { int num_apples, num_pizzas, num_donuts, num_ice_cream_cones; std::cout << "Enter the number of apples: "; std::cin >> num_apples; std::cout << "Enter the number of pizzas: "; std::cin >> num_pizzas; std::cout << "Enter the number of donuts: "; std::cin >> num_donuts; std::cout << "Enter the number of ice cream cones: "; std::cin >> num_ice_cream_cones; double total_volume = num_apples * VolSphere(1.5) + num_pizzas * VolCylinder(6, 0.25) + num_donuts * VolDonut(2, 0.5) + num_ice_cream_cones * (VolCone(1, 5) + VolSphere(1.25)); std::cout << "Total volume of food you will eat: " << total_volume << " cubic inches" << std::endl; return 0; } // lol.cpp #include #include std::string LOLSpeak(std::string S, std::string Abbr, std::string Translation) { size_t pos = S.find(Abbr); while (pos != std::string::npos) { S.replace(pos, Abbr.length(), Translation); pos = S.find(Abbr, pos + Translation.length()); } return S; } int main() { std::string sentence; std::cout << "Enter a sentence: "; getline(std::cin, sentence); sentence = LOLSpeak(sentence, " u ", " you "); sentence = LOLSpeak(sentence, " lol ", " laughing out loud "); sentence = LOLSpeak(sentence, " brb ", " be right back "); // Add your own additional abbreviations and translations here std::cout << "Corrected sentence: " << sentence << std::endl; return 0; }

Sample Answer