Code for the problem
#include <iostream>
using namespace std;
class Vehicle{
protected:
int base_weight;
int passengers;
public:
Vehicle(int b, int p){
base_weight=b;
passengers=p;
}
void total_weight(int arr[], int p1){
int sum=0;
for(int i=0;i<p1;i++){
if(i<passengers){
sum+=arr[i];
}
}
//cout<<sum<<" "<<base_weight<<endl;
cout<<(sum+base_weight)<<" ";
}
};
class Cargo:public Vehicle{
private:
int cargo_capacity;
public:
Cargo(int b, int p, int c):Vehicle(b,p){
cargo_capacity=c;
}
void total_weight(int arr1[], int p1, int arr2[], int c2){
int sum=0;
for(int i=0;i<p1;i++){
sum+=arr1[i];
}
//Sort array in descending order
for(int i=0;i<(c2-1);i++){
for(int j=(i+1);j<c2;j++){
if(arr2[i]<arr2[j]){
int temp=arr2[i];
arr2[i]=arr2[j];
arr2[j]=temp;
}
}
}
// for(int i=0;i<c2;i++){
// cout<<arr2[i]<<" "<<endl;
// }
int temp=0;
int sum_capacity=0;
for(int i=0;i<c2;i++){
if(arr2[i]<cargo_capacity){
temp=arr2[i];
if(arr2[i]>sum_capacity){sum_capacity=arr2[i];}
for(int j=i+1;j<c2;j++){
if((temp+arr2[j])<cargo_capacity){
temp+=arr2[j];
}
}
if(sum_capacity<temp){
sum_capacity=temp;
}
}
}
//cout<<sum_capacity<<" "<<endl;
cout<<(sum+base_weight+sum_capacity)<<" ";
}
};
int main()
{
int a1, a2, a3, a4, a5;
cin>>a1;
cin>>a2;
cin>>a3;
cin>>a4;
cin>>a5;
Vehicle vehicle(a1,a2);
Cargo cargo(a3,a4,a5);
int p1, p2, c2;
cin>>p1;
int arr1[p1];
for(int i=0;i<p1;i++){
cin>>arr1[i];
}
//cout<<"\nkhjhk\n";
cin>>p2;
int arr2[p2];
for(int i=0;i<p2;i++){
cin>>arr2[i];
}
//cout<<"\njkej "<<p2<<endl;
cin>>c2;
int arr3[c2];
for(int i=0;i<c2;i++){
cin>>arr3[i];
}
// cout<<"\njkej "<<c2<<endl;
vehicle.total_weight(arr1, p1);
cargo.total_weight(arr2,p2,arr3,c2);
return 0;
}
Screenshot of code:
Screenshot of output:
C++ Assignment Write a program that calculates the total weight of one vehidle and one cargo...
c++ please Assignment Write a program that calculates the quality of a home composed of three rooms. For each room, the user will give the width and depth information as two doubles, the unusable amount of space within the room as a double, the fact that the door opens inward or outward as a boolean (1 means inward), and the number of windows as an integer. Based on this information the program should calculate the total usable size of the...
USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user indicate the weight and quantity of the boxes. The program computes and prints the total cargo weight The output should match the sample below. Make sure you print the input number (Input #1, Input #2,) 3 - Input # 1. Weight of the box (lbs): 4 Enter quantity: 2 Input #2. Weight of the...
I need a simple program in C language that calculates the values of Sine, Cosine, and Tangent of values given in degrees. It has to be a range of values between 0 and 360(integer values). The output should be a table of values showing Sin, Cos and Tan values. The complete computation and printing of the table must be done inside a function. The function also returns to the main program with 3 output arguments: It also needs to show...
Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...
Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new base class. This will be the base for two classes created through inheritance. The Cargo class will need to have virtual functions in order to have them redefined in the child classes. You will be able to use many parts of the new Cargo class in the child classes since they will have the same arguments/parameters and the same functionality. Child class one will...
How to solve this Problem in C++ . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...
Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...
Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...
C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of...
what would be the solution code to this problem in c++? The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of...