Java Question

Description

Please rename file as: Maryam – Jumah – 900595648 – CSC262.docx

Don't use plagiarized sources. Get Your Custom Assignment on
Java Question
From as Little as $13/Page

Unformatted Attachment Preview

CSC252 Programming in C++
How to submit your Assignment
After filling all the parts in this file, please follow the following steps.
1. Add your name and ID to the first page.
2. Save the file in the original format (Docx or Doc)
i. (please do not convert to other file formats e.g. PDF, ZIP, RAR, …).
3. Rename the file as
i. YOUR First Name – YOUR Last Name- YOUR student IDCSC252.docx
ii. Example: John – Smith – 234566435 – CSC252.docx
4. Upload the file and submit it.
Problem 1 – Implement the Soda Can Class (25 points)
Write a program which implements a Soda can which is a cylinder. Add a constructor
create a soda can with parameter values for radius and height. Add two computing
accessors which return the volume and the surface area of the can. The formula for
the volume of a cylinder is:
= 2 ℎ
and the formula for the surface area of a cylinder is:
= 2 ℎ + 2 2
Where r is the radius and h is the height of the cylinder. If you compiler is at C++20 or
later, use std::numbers::pi for the value of pi, otherwise research the best way to
obtain the value.
Write a program that tests each function and displays the results of their use.
Design, edit, run, test, and debug your program. Enter the completed C++ code here:
C++ code for the lab project:
#include
#include
using namespace std;
class SodaCan {
public:
SodaCan(double radius, double height) : radius(radius),
height(height) {}
double getVolume() const {
return M_PI * radius * radius * height;
}
double getArea() const {
return 2 * M_PI * radius * (height + radius);
}
private:
double radius;
double height;
};
int main() {
double radius, height;
cout > radius;
cout > height;
SodaCan sodaCan(radius, height);
cout
Purchase answer to see full
attachment