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)
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....
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: ----------------------...
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
Create a Program Proposal for a program that deals with how ti mitigate stress. Information for...
Create a Program Proposal for a program that deals with how ti mitigate stress. Information for the following aspects of your program program should include: Title, Goals/Objective, Description, Evaluation, Justification, Duriation, Resources and Budget.
West Coast Containers manufactures a high quality container in which to ship electronic equipment. Actual production...
West Coast Containers manufactures a high quality container in which to ship electronic equipment. Actual production was 18,000 containers using 9,500 machine-hours. Actual variable costs were $20 per machine-hour. The current year operating budget is based on production of 20,000 containers with 0.8 machine-hour allowed per container. Variable manufacturing overhead is anticipated to be $220,000. Calculate the variable overhead rate and efficiency variances. Calculations s/b 2 decimal places.
For this problem, imagine that you are on a ship that is oscillating up and down...
For this problem, imagine that you are on a ship that is oscillating up and down on a rough sea. Assume for simplicity that this is simple harmonic motion (in the vertical direction) with amplitude 5 cm and frequency 2 Hz. There is a box on the floor with mass m = 1kg. (a)Assuming the box remains in contact with the floor throughout, find the maximum and minimum values of the normal force exerted on it by the floor over...
Create a program that generates random number between 0 and 50 and puts them into a...
Create a program that generates random number between 0 and 50 and puts them into a linked list. When it generates 49, instead of adding it to the list, it prints the list, freeing each node and then exits. Submit your .c file
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT