Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Topics covered: Writing Programs From Scratch Objective: The objective of this l

ID: 3690751 • Letter: T

Question

Topics covered: Writing Programs From Scratch

Objective:

The objective of this lab is to give you more experience writing entire programs from scratch. We will be providing you skeleton development environment (basically empty .cpp files and a makefile to compile them) and you will create a fully functional program according to our specifications.

You will be given 4 short problems. These problems will need to be solved using a straight function based approach or a C++ class based approach.

You have to solve two of them using a C++ class based approach. The other two will have to be solved using functions (no classes except for standard C++ library classes).

For each program main() should contain the minimal logic necessary to solve these problems. For the class based projects most of the programming should be completed within the class itself. For the function based programs main() will need to contain more of the logic. However, you are encouraged to do the majority of the programming within separate functions.

Specifications:

In this homework you will be developing four programs. pyramid.cpp, prism.cpp, cubiod.cpp, and breakup-strings.cpp

The first three programs will be using the following geometric shapes:

Triangular Pyramid

Triangular Prism

Cuboid

You will need to prompt the user for the necessary information to calculate the surface area and the volume of these shapes. Please provide hand calculations to verify your program's output. You will scan these calculations to a PDF document or submit a word doc with your calculations to GITHUB.

The last program will implement functions to work with a comma separated list of works.

Given a comma separated string such as the following:

xyz,yuo,gho,kyo,etc,

Break the large string into individual strings demarcated by a comma and store them into a vector. Please consider using the find and substr functions of a C++ string to perform this task.

Once you have the vector write functions to do the following:

Produce a count of words that start with a specific letter (case insensitive)

Produce a count of words that contain a specific letter

Return the first string in the vector that contains a specific letter. Please return proper error code if a string is not found.

Return the first string that is alphabetically the largest (use the > operator)

Return the ASCII sum of all letters in a specific string

Write a main() to exercise these functions. They should all be called at least once.

All classes should have appropriate setters, getters, constructors, and print/display functions.

Your main() function should test all your functions and/or classes.

Task 1:

Develop your own solution to each problem.

In the github folder for this assignment you will have four starter .cpp files. They are called breakup-strings.cpp, cubiod.cpp, prism.cpp, and pyramid.cpp. Each file is empty. You can create executables for all of them by typing “make” by itself. If you want to make a specific program just type “make prism” or “make cubiod’, etc.

Note: No executables will be created until you edit each file to add a main()

Explanation / Answer

Pyramid.cpp:

#include <cmath> // for pow functions

using namespace std;
class Pyramid
{
    float pyramidBaseLength;
float pyramidHeight;
float pyramidSlantHeight;
float pyramidSurfaceArea;
float pyramidVolume;
float baseSquared;
public:
    Pyramid(float b,float h)
    {
        pyramidBaseLength=b;
            pyramidHeight=h;
           baseSquared= pow(pyramidBaseLength , 2);
        pyramidSlantHeight= sqrt(pow( pyramidHeight , 2) + (0.25 * baseSquared));
       }
   
    float SurfaceArea()
    {
        pyramidSurfaceArea= pyramidBaseLength* (pyramidBaseLength + sqrt(baseSquared + 4 * pow( pyramidHeight , 2)));
return pyramidSurfaceArea;
   }
   float volume()
   {
      pyramidVolume= (baseSquared * pyramidHeight) / 3;
      return pyramidVolume;
   }
}
;

Prism.cpp:

include <iomanip> // for formatting output
#include <cmath> // for pow functions

using namespace std;
class Prism
{
    double Altitude,Base,Height;
double s1, s2, s3;
public:
    Pyramid(double a,double b, double h, double s,double si, double sj)
    {
        Altitude=a;
       
           Base=b;
           Height=h;
           s1=s;
               s2=si;
               s3=sj;
       }
   
    double SurfaceArea()
    {
       
return Altitude*Base + (s1 + s2 + s3)*Height;
   }
   double volume()
   {
      return (0.5)*Altitude*Base*Height;
   }
}

Cubiod.cpp:

#include <iomanip> // for formatting output
#include <cmath> // for pow functions

using namespace std;
class Cubiod
{
    float width, length, height;
float surfacearea, volume;
public:
    Cubiod(float w,float l,float h)
    {
        width=w;
           length=l;
           height=h;
       }
   
    float SurfaceArea()
    {
   
return 2 *(width * length + length * height + height * width);;
   }
   float volume()
   {
      return width * length * height;
   }
}

Breakup_strings.cpp:

#include <vector>
#include <string>
#include <sstream>

using namespace std;

class Breakup_strings
{
std::string str="Split me by whitespaces";
std::string buf; // Have a buffer string
public:
  
Breakup_strings(string s)
{
   str=s;
   }
   vector<std::string> breakup_strings()
   {
       char sep=',';
       std::vector<std::string> tokens;
       std::size_t start = 0, end = 0;
       while ((end = str.find(sep, start)) != std::string::npos) {
       std::string temp = str.substr(start, end - start);
       if (temp != "")
                   tokens.push_back(temp);
       start = end + 1;
       }
       std::string temp = str.substr(start);
       if (temp != "")
               tokens.push_back(temp);
       return tokens;
}
};

main.cpp:

#include<iostream>
#include <vector>
#include <string>
#include <iomanip>
#include "Pyramid.cpp"
int main()
{
   Pyramid p(5.2,4.0);
   Cubiod c(3.0, 7.0, 6.0);
   Breakup_strings b("Split me by whitespaces");
   Prism pr(1.2 ,4.0 ,3.0 ,7.0 ,6.0 ,4.0);
   cout<<"Surface area of Pyramid is: %.3f",p.SurfaceArea();
   cout<<"volume of pyramid is: %.3f",p.volume();
  
   cout<<"Surface area of prism is: %.3f",pr.SurfaceArea();
   cout<<"volume of prism is: %.3f",pr.volume();
  
   cout<<"Surface area of cuboids is: %.3f",c.SurfaceArea();
   cout<<"volume of cuboids is: %.3f",c.volume();
  
   cout<<"Break the large string into individual strings demarcated by a comma ",b.breakup-strings();
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote