Question

In: Electrical Engineering

Create a program that stores the information of up to 50 containers loaded on ship. The...

Create a program that stores the information of up to 50 containers loaded on ship. The program should contain a menu to do the following:

A or a     to add a container.

R or r      to retrieve the information of one container.

T or t      to retrieve the information of all containers.

W or w   to retrieve the total weight of the loaded containers.

X or x      to exit the program

Ask the user for the number of containers to be loaded, create an array of floats with five rows and a number of columns equal to the number of containers provided by the user.

Option A: for this option check if the array has an empty column to enter the information for a container, if not, output a message indicating that array is full. If array is not full, ask the user for the ID number, length in meters, width in meter, height in meters, and weight in Kg of the container and store them in the array.

Option R: Ask the user for the desired ID number to be searched. If found, output the ID number, length in meters, width in meter, height in meters, weight in Kg, and volume in cubic meters of the container each on a line. If not found, display a message to that effect.

Option T: retrieve the info for all containers in the array with a dotted line separating one another. The info retrieved and calculated should be the same as the above step.

Option W: display the total weight of all the containers in the array.

Option X: Exit the program.

Solutions

Expert Solution

code:

#include <stdio.h>

int main() {

//code

int n; //represent the number of containers to be loaded.\n");

printf("Enter the number of containers to be loaded.\n");

scanf("%d",&n);

float arr [5][n];

int i;

for(i=0;i<4;i++) //initialization of array .here -1 represent empty cell.

{

int j;

for( j=0;j<n;j++)

arr[i][j]=-1;

}

printf(" Menu ....\n A or a :to add a container.\n R or r :to retrieve the information of one container.\n T or t :to retrieve the information of all containers.\n W or w :to retrieve the total weight of the loaded containers.\n X or x :to exit the program\n");

char ch;

do

{

fflush(stdin); //use to clear the buffer

printf("\n Select Operation...\n ..........................\n");

scanf("%c",&ch);

if(ch=='A' || ch=='a')

{

int i=0;

for(;i<n;i++)

{

if(arr[0][i]==-1)

break;

}

if(i==n)

printf("Array is full..\n");

else

{

printf("Enter ID number.\n");

scanf("%f",&arr[0][i]);

printf("Length in meters\n");

scanf("%f",&arr[1][i]);

printf("Width in meter . \n ");

scanf("%f",&arr[2][i]);

printf("Height in meters.\n");

scanf("%f",&arr[3][i]);

printf("Weight in Kg \n");

scanf("%f",&arr[4][i]);

}

}

if(ch=='R' || ch=='r')

{

float id;

printf("Enter the ID number to be searched..\n");

scanf("%f",&id);

int i=0;

for(;i<n;i++)

{

if(arr[0][i]==id)

break;

}

if(i==n)

printf("The container which Id number is %f not loaded.\n",id);

else

{

printf("ID number: %f\n length in meters: %f \n width in meter : %f \n height in meters : %f \n weight in Kg : %f \n volume :%f\n",arr[0][i],arr[1][i],arr[2][i],arr[3][i],arr[4][i],arr[1][i]*arr[2][i]*arr[3][i]);

}

}

if(ch=='T' || ch=='t')

{

int i;

for(i=0;i<n;i++)

{

printf(" Containers %d\n ",i+1);

printf("ID number: %f\n length in meters: %f \n width in meter : %f \n height in meters : %f \n weight in Kg : %f \n",arr[0][i],arr[1][i],arr[2][i],arr[3][i],arr[4][i]);

printf(".............................................................................\n");

}

}

if(ch=='W' || ch=='w')

{

float total_weight;

int i;

for( i=0;i<n;i++)

{

if(arr[4][i]!=-1)

total_weight+=arr[4][i];

}

printf("total_weight=%f",total_weight);

}

}while(ch!='X' && ch!='x');

return 0;

}


Related Solutions

C++ program Dairy Farm decided to ship milk in containers in the form of cubes rather...
C++ program Dairy Farm decided to ship milk in containers in the form of cubes rather than cylinders. Write a program that prompts the user to input: The radius of the base of a cylindrical container The height of the cylindrical container The program then outputs: The side of the cube with the same volume as the cylindrical container with a precision of 2 decimal places. You may assume that the value of π = 3.141593.
Create a class named Ship with a field that stores a collection of Shippable things and...
Create a class named Ship with a field that stores a collection of Shippable things and another that stores a maximum weight capacity. Include a constructor with a parameter for the max weight, and that gives the Ship an empty collection of Shippables. (Javascript)
Create a class named Ship with a field that stores a collection of Shippable things and...
Create a class named Ship with a field that stores a collection of Shippable things and another that stores a maximum weight capacity. Include a constructor with a parameter for the max weight, and that gives the Ship an empty collection of Shippables. (Javascript)
Create the logic for a program that stores 5 names in an array. Your program will...
Create the logic for a program that stores 5 names in an array. Your program will then ask the user which name (s)he wants to search. The program receives the name to be searched as input and searches the array for the name entered. If the name is one of the names in the array, display the message "Name found.". Otherwise, display the message "Name not found.". in pseudocode please in python
At We Ship Anything, we need to create a program that will calculate the charges associated...
At We Ship Anything, we need to create a program that will calculate the charges associated with the weight of a specific package. We charge a base rate of $54.03 for any package and then add a premium to it based on the package weight. The additional costs are as follows: • If the package weighs less than 2.5 kg then we charge an additional $2.00. • If the package weighs 2.5kg to 5kg then we charge an additional $3.00....
In C create a program that stores contact info. The program must have the following features:...
In C create a program that stores contact info. The program must have the following features: Able to store First Name, Phone Number and Birthday (MM/DD/YYYY) Able to search for a specific contact using First Name, Phone Number and Birthday (find) Able to delete a specific contact using First Name, Phone Number and Birthday (delete) Print entire contact list Show number of entries in contact list Able to save Contact List to file (save) Able to load Contact List from...
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Instructions Write a program that prompts the user to enter 50 integers and stores them in...
Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Java (a) Create a class Router which stores the information of a router. It includes the...
Java (a) Create a class Router which stores the information of a router. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Router object is created. Also write the getter methods for those variables. Finally add a method toString() to return the router information in the following string form. "brand: Linksys, model number: RVS4000, price: 1080.0" Copy the content...
(a) Create a class Webcam which stores the information of a webcam. It includes the brand,...
(a) Create a class Webcam which stores the information of a webcam. It includes the brand, the model number (String) and the price (double, in dollars). Write a constructor of the class to so that the information mentioned is initialized when a Webcam object is created. Also write the getter methods for those variables. Finally add a method toString() to return the webcam information in the following string form. "brand: Logitech, model number: B525, price: 450.0" Copy the content of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT