A big oil company is using three different types of tanks; cuboidal, cylindrical
ID: 3681636 • Letter: A
Question
A big oil company is using three different types of tanks; cuboidal, cylindrical, and regular right hexagonal prism. The company only charges customers for the fuel which it puts in the tank. Therefore, the company wants one of its programmers to write a C++ program to implement the properties (private variables) and behavior (public methods) of the three different tanks. In your program, you must use three different classes, one for each tank type. Your class should have some instance variables to store the tank’s dimension measured in feet. The initial values are given in parentheses.
First set of ADTs
In case of cuboidal tanks class:
these are length (10), width (6) and height (400) and the liquidHeight (initially 0). You may add other properties you see necessary.
In case of cylindrical tank class: these are base radius (6) and height (400) and the liquidHeight (initially 0). You may add other properties you see necessary.
In case of the regular right hexagonal prism class: these are base edge (6) and height (400) and the liquidHeight (initially 0). You may add other properties you see necessary.
You must use member functions of the appropriate class to help the company to:
1. To get the maximum possible volume
2. To get the current volume
3. To supply oil (change liquidHeight)
4. To get the amount of oil to completely fill tank (max possible volume - current volume)
5. To get the amount of oil to partially fill tank (new volume - current volume)
Second set of ADTs
The second set of ADTs you have to implement are: an Operator (class) ADT and a main function to test all the ADTs. The Operator ADT should consist of a struct to represent operator details which are:
ID (a nine digit number)
first name
last name
employment date (a date of form MM:DD:YYYY - must be represented by a struct)
role (a single character)
All the operators data are provided in a file: operators.txt. Each line in the file represents an operator record. The first line in the file states the number of records. The Operator member function should provide the following capabilities:
1. To print all operators
2. To print only operators with a given role character
3. To print only operators with a given employment year
4. To print only operators with a given employment month
5. To print only operators with a given employment day The main function should provide a menu to test all the capabilities.
The main menu provides 2 submenu - Manager and Operator Menu:
Explanation / Answer
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
class cuboidal{
public:
cuboidal(){
length=10;
width=6;
height=400;
}
cuboidal(int l, int w, int h){
length=l;
width=w;
height=h;
}
int maxVolume(){
return length*width*height;
}
int currentVolume(){
return length*width*liquidHeight;
}
int changeLiquidHeight(int h){
liquidHeight=h;
}
int amountToCompletelyFillTank(){
return maxVolume()-currentVolume();
}
int amountToPartiallyFillTank(int h){
return (length*width*h)-(currentVolume());
}
private:
int length, width, height;
int liquidHeight;
};
class cylindrical{
public:
cylindrical(){
radius=6;
height=400;
}
cylindrical(int r, int h){
radius=r;
height=h;
}
int maxVolume(){
return 3.14*radius*radius*height;
}
int currentVolume(){
return 3.14*radius*radius*liquidHeight;
}
int changeLiquidHeight(int h){
liquidHeight=h;
}
int amountToCompletelyFillTank(){
return maxVolume()-currentVolume();
}
int amountToPartiallyFillTank(int h){
return (3.14*radius*radius*h)-(currentVolume());
}
private:
int radius, height;
int liquidHeight;
};
class hexagonal{
public:
hexagonal(){
base=6;
height=400;
}
hexagonal(int b, int h){
base=b;
height=h;
}
int maxVolume(){
return 2.6*base*base*height;
}
int currentVolume(){
return 2.6*base*base*liquidHeight;
}
int changeLiquidHeight(int h){
liquidHeight=h;
}
int amountToCompletelyFillTank(){
return maxVolume()-currentVolume();
}
int amountToPartiallyFillTank(int h){
return (2.6*base*base*h)-(currentVolume());
}
private:
int base, height;
int liquidHeight;
};
class operators{
private:
int id;
string firstName, lastName;
struct _date{
int month;
int day;
int year;
}emplymentDate;
char role;
public:
void printAllOperators(){
ifstream input( "operators.txt" );
int i=0;
for( string line; getline( input, line ); ){
if(i!=0){
istringstream iss(line);
string id,fName, sName, date,r;
iss>>id>>fName>>sName>>date>>r;
cout<<fName<<" "<<sName<<endl;
}
i=1;
}
}
void printOperatorsWithGivenRole(string role){
ifstream input( "operators.txt" );
int i=0;
for( string line; getline( input, line ); ){
if(i!=0){
istringstream iss(line);
string id,fName, sName, date,r;
iss>>id>>fName>>sName>>date>>r;
if(role.compare(r) ==0){
cout<<fName<<" "<<sName<<endl;
}
}
i=1;
}
}
void printAllOperatorsGivenYear(int year){
ifstream input( "operators.txt" );
int t=0;
for( string line; getline( input, line ); ){
if(t!=0){
istringstream iss(line);
string id,fName, sName, date,r;
iss>>id>>fName>>sName>>date>>r;
stringstream ss(date);
int i;
vector<int> vec;
while (ss >> i){
vec.push_back(i);
if (ss.peek() == ':')
ss.ignore();
}
if(vec[2]==year){
cout<<fName<<" "<<sName<<endl;
}
}
t=1;
}
}
void printAllOperatorsGivenMonth(int month){
ifstream input( "operators.txt" );
int t=0;
for( string line; getline( input, line ); ){
if(t!=0){
istringstream iss(line);
string id,fName, sName, date,r;
iss>>id>>fName>>sName>>date>>r;
stringstream ss(date);
int i;
vector<int> vec;
while (ss >> i){
vec.push_back(i);
if (ss.peek() == ':')
ss.ignore();
}
if(vec[0]==month){
cout<<fName<<" "<<sName<<endl;
}
}
t=1;
}
}
void printAllOperatorsGivenDay(int day){
ifstream input( "operators.txt" );
int t=0;
for( string line; getline( input, line ); ){
if(t!=0){
istringstream iss(line);
string id,fName, sName, date,r;
iss>>id>>fName>>sName>>date>>r;
stringstream ss(date);
int i;
vector<int> vec;
while (ss >> i){
vec.push_back(i);
if (ss.peek() == ':')
ss.ignore();
}
if(vec[1]==day){
cout<<fName<<" "<<sName<<endl;
}
}
t=1;
}
}
};
int main(){
int n;
cout<<"Enter: 1 for Manager, 2 for Operator, else Exit"<<endl;
cin>>n;
if(n==1){
cuboidal cub;
cout<<"Maximum cuboidal tank's height is: "<<cub.maxVolume()<<endl;
cub.changeLiquidHeight(300);
cout<<"liquidHeight of cuboidal tank is changed!!"<<endl;
cout<<"Current Volume of cuboidal tank is: "<<cub.currentVolume()<<endl;
cout<<"Amount of oil required to completely fill the cuboidal tank is: "<<cub.amountToCompletelyFillTank()<<endl;
cout<<"Amount of oil required to partially fill the cuboidal tank is: "<<cub.amountToPartiallyFillTank(500)<<endl;
}
else if(n==2){
operators opt; //A file named "operators.txt" should be present in the same folder
opt.printAllOperators(); //You can change the function name here to print based on day, month, etc
}
else{
cout<<"You are Done!!"<<endl;
return 0;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.