Question

In: Computer Science

Do the problems found week 4 - Programs 1,2,3,4,5,6 and 7.        * Be sure to...

Do the problems found week 4 - Programs 1,2,3,4,5,6 and 7.

       * Be sure to add your name as a cout in the first lines of each program - else 0 credit.

       * Add constructors - a default and parameterized constructor to each.

       * Write an .h interface and a .cpp implementation for each class

       * Write an Drive/Test file that tests the constructors and functions

      * Write a UML class diagram for each class\!!!!!!

Program 6

#include<iostream>

using namespace std;

class Box

{

public:

    Box() {

        Length = 0;

        Width = 0;

        Height = 0;

    }

    double Length;

    double Width;

    double Height;

    double Volume();

    double SurfaceArea();

    void setWidth ( double n ) {Width = n;}

    void setDepth ( double n ) {Length = n;}

    void setHeight ( double n ) {Height = n;}

    double getWidth () {return Width;}

    double getHeight () {return Height;}

    double getDepth () {return Length;}

    double calcArea () {return 2*(Length*(Width+Height)+Width*Height);}

    double calcVolume () {return Length*Width*Height;}

};

int main() {

    cout<<"-------- ";

    

    Box B1;

    B1.setWidth(2);

    B1.setDepth(4);

    B1.setHeight(9);

    cout << "Height = " << B1.getHeight() << endl;

    cout << "Area = " << B1.calcArea() << endl;

    cout << "Volume = " << B1.calcVolume() << endl;

    Box B2;

    B2.setWidth(3);

    B2.setDepth(5);

    B2.setHeight(10);

    cout << "Height = " << B1.getHeight() << endl;

    cout << "Area = " << B1. calcArea() << endl;

    cout << "Volume = " << B1.calcVolume() << endl;

}

program 7

#include <iostream>

using namespace std;

int main() {

    

    /*

     * Circumference = π × diameter = 2 × π × radius

     * Area : π r²

     * Diameter : 2r

     */

    cout<< "Name: "<< endl;

    double radius = 0;

    cout << "Enter radius of circle: ";

    cin >> radius;

    

    

    if (radius <= 0) {

        cout << "Please Enter radius greater than zero" << endl;

        return 0;

    }

    

    double pie = 22/7.0;

    double circumference = 2 * pie * radius;

    double area = pie * radius * radius;

    double diameter = 2 * radius;

    cout << "Circumference of Circle:" << circumference << endl;

    cout << "Area of Circle:" << area << endl;

    cout << "Diameter of Circle:" << diameter << endl;

    cout << "Radius of Circle:" << radius << endl;

    

    return 0;

}

program 2


#include <iostream>

#include <string>

using namespace std;

class myClass{

public:

    void setName(string x){

        name = x ;

    }

    string getName(){

        return name;

    

    }

private:

    string name;

};

int main()

{

    cout<<"----";

    myClass to;

    to.setName("stuff are cool ");

    cout << to.getName();

    return 0;

}

Solutions

Expert Solution

Program 6:
//Box.h
#include<iostream>
using namespace std;
class Box
{
public:
   double Length;
   double Width;
   double Height;
public:
   //Default constructor
   Box();
   //Parameterized constructor
   Box(double ,double,double);

   //Setter methods
   void setWidth ( double n ) ;
   void setDepth ( double n ) ;
   void setHeight ( double n );
   //getter methods
   double getWidth () ;
   double getHeight ();
   double getDepth () ;
   //Methods to calculate area and volume of box
   double calcArea () ;
   double calcVolume () ;
};
--------------------------------------------------
//Box.cpp
#include <iostream>
#include "Box.h"
using namespace std;
//default constructor
Box::Box()
{
   Length = 0;
   Width = 0;
   Height = 0;
}
//parameterized constructor
Box::Box(double l,double w, double h)
{
   Length = l;
   Width = w;
   Height = h;
}
void Box::setWidth ( double n )
{
   Width = n;
}
void Box::setDepth ( double n )
{
   Length = n;
}
void Box::setHeight ( double n )
{
   Height = n;
}
double Box::getWidth ()
{
   return Width;
}

double Box::getHeight ()
{
   return Height;
}
double Box::getDepth ()
{
   return Length;
}
double Box::calcArea ()
{
   return 2*(Length*(Width+Height)+Width*Height);
}
double Box::calcVolume ()
{
   return Length*Width*Height;
}
--------------------------------------------------
//main.cpp
#include<iostream>
#include<string>
#include "Box.h"
using namespace std;
//start of main method
int main()
{
   string myName= "yourname";
    cout<<"Name: "<<myName<<endl;

   //default constructor
    Box B1;
   cout<<"Testing default constructor"<<endl;
    cout << "Height = " << B1.getHeight() << endl;
    cout << "Area = " << B1.calcArea() << endl;
    cout << "Volume = " << B1.calcVolume() << endl;

   //parmeter constructor
    Box B2(1,2,3);
   cout<<"Testing parameterized constructor"<<endl;
    cout << "Height = " << B2.getHeight() << endl;
    cout << "Area = " << B2.calcArea() << endl;
    cout << "Volume = " << B2.calcVolume() << endl;

    Box B3;
    B3.setWidth(3);
    B3.setDepth(5);
    B3.setHeight(10);
   cout<<"Testing functions "<<endl;
    cout << "Height = " << B3.getHeight() << endl;
    cout << "Area = " << B3. calcArea() << endl;
    cout << "Volume = " << B3.calcVolume() << endl;

   system("pause");
   return 0;

}
--------------------------------------------------
Sample Output:
Name: yourname
Testing default constructor
Height = 0
Area = 0
Volume = 0
Testing parameterized constructor
Height = 3
Area = 22
Volume = 6
Testing functions
Height = 10
Area = 190
Volume = 150

UML class diagram for Box

-------------------------------------------------
Program 7:
//Circle.h
#include<iostream>
using namespace std;
class Circle
{
public:
   double radius;
public:
   //Default constructor
   Circle();
   //Parameterized constructor
   Circle(double );

   //Setter methods
   void setRadius ( double n ) ;
   //Setter methods
   double getRadius () ;

   //Methods to calculate area and volume of box
   double calcCircumference() ;
   double calcArea () ;
   double calDiameter();
};

-----------------------------------------------
//Circle.cpp
#include<iostream>
#include "Circle.h"
using namespace std;
//Default constructor
Circle::Circle()
{
   radius=0;
}
//Parameterized constructor
Circle::Circle(double r)
{
   radius=r;
}
//Setter methods
void Circle::setRadius ( double r )
{
   radius=r;
}
//Getter method
double Circle::getRadius ( )
{
   return radius;
}
double Circle::calcCircumference()
{
   return 2 * 3.14 * radius;
}
double Circle::calcArea ()
{
   return 3.14 * radius * radius;
}
double Circle::calDiameter()
{
   return 2 * radius;
}
-----------------------------------------------


//main2.cpp
#include <iostream>
#include "Circle.h"
using namespace std;
int main()
{
    cout<< "Name: "<< endl;
    double radius = 0;
    cout << "Enter radius of circle: ";
    cin >> radius;
  
   //declare Circle class object,c
   Circle c;
   c.setRadius(radius);
   cout << "Radius of Circle:" << c.getRadius()<< endl;
   cout << "Circumference of Circle:" << c.calcCircumference() << endl;
   cout << "Area of Circle:" << c.calcArea() << endl;
   cout << "Diameter of Circle:" << c.calDiameter() << endl;

   system("pause");
    return 0;
}
-----------------------------------------------
Sample Output:

Name:
Enter radius of circle: 10
Radius of Circle:10
Circumference of Circle:62.8
Area of Circle:314
Diameter of Circle:20

UML class digram for Circle class:

-----------------------------------------------

Program 2:
//myClass.h
#include <iostream>
#include <string>
using namespace std;
class myClass
{
public:
    void setName(string x);
    string getName();
private:
    string name;
};

-----------------------------------------------
//myClass.cpp
#include<iostream>
#include<string>
#include "myClass.h"
using namespace std;
void myClass::setName(string x)
{
   name = x ;
}
string myClass::getName()
{
   return name;
}
-----------------------------------------------

//main3.cpp
#include<iostream>
#include<string>
#include "myClass.h"
using namespace std;
int main()
{
   cout<<"----";
   myClass to;
   to.setName("stuff are cool ");
   cout << to.getName();

   system("pause");
   return 0;

}
-----------------------------------------------
Sample Output:
"stuff are cool

UML class diagram for myClass class


Related Solutions

Do the problems found week 4 - Programs 1,2,3,4,5,6 and 7.        * Be sure to...
Do the problems found week 4 - Programs 1,2,3,4,5,6 and 7.        * Be sure to add your name as a cout in the first lines of each program - else 0 credit.        * Add constructors - a default and parameterized constructor to each.        * Write an .h interface and a .cpp implementation for each class        * Write an Drive/Test file that tests the constructors and functions        * Write a UML class diagram for each class...
This week will discuss TRICARE and managed care workers compensation programs. Be sure to answer questions...
This week will discuss TRICARE and managed care workers compensation programs. Be sure to answer questions for both of these topics in your initial response to the Discussion Board. TRICARE: What are three health care options of TRICARE? What is the role of a TRICARE PCM (Primary Care Manager)? Workers Compensation: Review the definition of managed care in Chapter 3, and also read page 619 before responding to the following: List at least 3 benefits from incorporating managed care into...
C++ Programming Convert problems 6 in to template classes, of week 5 and week 4. Test...
C++ Programming Convert problems 6 in to template classes, of week 5 and week 4. Test each with Implicit int, float, double, long int. Test each with explicit int, float, double, long int. Problem 6: //Box.h #include<iostream> using namespace std; class Box { public:    double Length;    double Width;    double Height; public:    //Default constructor    Box();    //Parameterized constructor    Box(double ,double,double);    //Setter methods    void setWidth ( double n ) ;    void setDepth ( double n ) ;    void setHeight ( double n );...
Provide a brief explanation of the accrediting or regulatory body you found in week 7; what...
Provide a brief explanation of the accrediting or regulatory body you found in week 7; what area of health care does the agency work in, what are their primary aims and what is its brief history? Who accredits the accreditors? J ust think about that one for a moment. Mostly it is the government (state and federal) but are there other quasi-governmental agencies or groups? What is the value of regulation and accreditation? Does regulation help or hinder efficiency? Quality?...
Business ethics This week we are covering the textbook topics found in Chapter 4, The Nature...
Business ethics This week we are covering the textbook topics found in Chapter 4, The Nature of Capitalism (beginning on page 117) and Chapter 5 Corporation (beginning on page 156). For this week’s discussion you need to post your thoughts on the following questions. Per our textbook, there are four key features of capitalism which include the existence of companies, the goal of making a profit, a competitive market, and private property ownership. How do these four features of capitalism...
Use the financial statements below for problems 4 to 7                               Balance Sheet Assets
Use the financial statements below for problems 4 to 7                               Balance Sheet Assets 2017 2018 Cash $14,000 $9,282 Short-term investments. 48,600 18,000 Accounts receivable 351,200 632,160 Inventories 710,200 1,287,360    Total current assets $1,124,000 $1,946,802 Gross fixed assets 491,000 1,202,950 Less: accumulated depreciation 146,200 263,160    Net fixed assets $344,800 $939,790 Total assets $1,468,800 $2,886,592 Liabilities and equity 2017 2018 Accounts payable $145,600 $324,000 Notes payable 200,000 720,000 Accruals 136,000 284,960    Total current liabilities $481,600 $1,328,960 Long-term debt...
Please do both problems. They are short. I will rate for sure. Thanks! Question# 1 Let...
Please do both problems. They are short. I will rate for sure. Thanks! Question# 1 Let p(x) = x^3 + 3x + 1 = (x + 3)^2 (x + 4) in Z5[x]. (a) Perform the following computations in Z5[x]/(p(x)). Give your answers in the form [r(x)] where r(x) has degree as small as possible. i. [4x] + [3x^2 + x + 2] ii. [x^2 ][2x^2 + 1] (b) Show that Z5[x]/(p(x)) has zero divisors Question #2 Let p(x) = x^3...
Question 2 (7 marks) (Note this question is from the Week 4 Tutorial) (a) What are...
Question 2 (Note this question is from the Week 4 Tutorial) (a) What are the most common reasons for a corporation to reduce its share capital? (b) What are the allowable methods of reducing share capital? (c) Discuss the differences between a share buyback and a capital reduction. (d) What are the different types of debt instruments discussed in this unit? (1 mark)
Week 4 lab A& P the muscular system 7. T or F The influx of sodium...
Week 4 lab A& P the muscular system 7. T or F The influx of sodium ions generates an action potential at the motor end plate 8. A ____ consist of a motor nerve fiber and all the muscle fibers it stimulates at neuromuscular junctions. 9. What is ACh? Explain what it is and it's function during the sequence of events at the neuromuscular junction. 18. The extensor digitorum longus muscle is located in the ___ compatment of the leg....
Module 4 Worksheet—Chapters 6 & 7 Please complete the problems in Excel on this worksheet and...
Module 4 Worksheet—Chapters 6 & 7 Please complete the problems in Excel on this worksheet and upload to the drop box for module 4 no later than Sunday, 11:55PM. Don’t round – use four decimal places until the final answer. 1. AA Corporation’s stock has a beta of 1.6. The risk-free rate is 2.5% and the expected return on the market is 14.5%. What is the required rate of return on AA’s stock? 3. Suppose you manage a $6 million...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT