question archive You are a civil engineer who wants to create a program to automatically calculate moments of inertia for common cross-sections

You are a civil engineer who wants to create a program to automatically calculate moments of inertia for common cross-sections

Subject:Computer SciencePrice:3.85 Bought3

You are a civil engineer who wants to create a program to automatically calculate moments of inertia for common cross-sections. Table 1 shows three common moments of inertia.

In the script file, perform the following tasks:
− Prompt the user for the shape (i.e., ‘R’, ‘H’, ‘C’). HINT: Use a switch/case structure for this decision.
− Display an error message stating the available options and end the program if the user does not enter a valid choice.
− Prompt the user for the axis of the moment of inertia (i.e., 1 for xx, 2 for yy) for the rectangle and hollow rectangular section.
− Prompt the user for the appropriate inputs
− Calculate the moment of inertia
− Print the section shape, moment of inertia, dimensions corresponding to Figure 1, and axis (where appropriate) about which the moment of inertia is being calculated clearly labeled and with proper units to the command window.

Table 1: Bacteria Count Classification Bacteria Classification Surface Area Covered by Bacteria (in2) Low X 2.5 Medium-Low 2.5 XS45 Medium 4.5 x 6.5 High High 6.5 8.5 8.33

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Dear Student,

Here is the program..

NOTE: Please note that the following program has been tested on ubuntu 14.04 system and compiled under gcc compiler.

-------------------------------------------------------------------------------------------------------------------------------------

program...

------------------------------------------------------------------------------------------------------------------------------------

//Header file declaration

#include<stdio.h>

#include<stdlib.h>

#include<math.h>

//starting of main function

int main()

{

//Varibale data type declaration

char code;

float b, d,b1,d1, Ixx, Iyy;

char axis;

printf("Please enter the Shape code: ");

float PI = 3.14;

scanf("%c",&code);

//switch to selected code

switch(code)

{

//Case R

case 'R':

printf("Please enter the axis: ");

scanf(" %c",&axis);

if(axis == 'x')

{

printf("PLease enter the value of dimension b: ");

scanf("%f",&b);

printf("PLease enter the value of dimesion d: ");

scanf("%f",&d);

Ixx = (b * pow(d, 3))/12;

printf("Section Shape is Rectangle.\n");

printf("Dimesion b is : %0.2f\n",b);

printf("Dimesion d is : %0.2f\n",d);

printf("Axis = xx\n");

printf("Moment of Inertia is: %0.2f\n",Ixx);

}

else if(axis == 'y')

{

printf("PLease enter the value of dimension d: ");

scanf("%f",&d);

printf("PLease enter the value of dimesion b: ");

scanf("%f",&b);

//Calculate Moment of Inertia

Iyy = (d * pow(b, 3))/12;

//Display Information

printf("Section Shape is Rectangle.\n");

printf("Dimesion d is : %0.2f\n",d);

printf("Dimesion b is : %0.2f\n",b);

printf("Axis = yy\n");

printf("Moment of Inertia is: %0.2f\n",Iyy);

}

break;

//Case H

case 'H':

printf("Please enter the axis: ");

scanf(" %c",&axis);

if(axis == 'x')

{

printf("PLease enter the value of dimension b: ");

scanf("%f",&b);

printf("PLease enter the value of dimesion d: ");

scanf("%f",&d);

printf("PLease enter the value of dimension b1: ");

scanf("%f",&b1);

printf("PLease enter the value of dimesion d1: ");

scanf("%f",&d1);


Ixx = (b * pow(d, 3))/12 - (b1 * pow(d1, 3))/12;

printf("Section Shape is Hollow Rectangular.\n");

printf("Dimesion b is : %0.2f\n",b);

printf("Dimesion d is : %0.2f\n",d);

printf("Dimesion b1 is : %0.2f\n",b1);

printf("Dimesion d1 is : %0.2f\n",d1);

printf("Axis = xx\n");

printf("Moment of Inertia is: %0.2f\n",Ixx);

}

else if(axis == 'y')

{

printf("PLease enter the value of dimension d: ");

scanf("%f",&d);

printf("PLease enter the value of dimesion b: ");

scanf("%f",&b);

printf("PLease enter the value of dimension d1: ");

scanf("%f",&d1);

printf("PLease enter the value of dimesion b1: ");

scanf("%f",&b1);


Iyy = (d * pow(b, 3))/12 - (d1 * pow(b1, 3))/12;

printf("Section Shape is Hollow Rectangular.\n");

printf("Dimesion d is : %0.2f\n",d);

printf("Dimesion b is : %0.2f\n",b);

printf("Dimesion d1 is : %0.2f\n",d1);

printf("Dimesion b1 is : %0.2f\n",b1);

printf("Axis = yy\n");

printf("Moment of Inertia is: %0.2f\n",Iyy);

}

break;

//Case C

case 'C':

printf("Please enter the axis: ");

scanf(" %c",&axis);

if(axis == 'x')

{

printf("Please enter the value of d: ");

scanf("%f", &d);

Ixx = (PI * pow(d,2))*64;

printf("Shape is = Circle\n");

printf("Dimesion d is = %f\n", d);

printf("Axis = xx\n");

printf("Moment of Inertia is: %0.2f\n",Ixx);

}

else if(axis == 'y')

{

printf("PLease enter the value of d: ");

scanf("%f", &d);

Iyy = (PI * pow(d,2))*64;

printf("Shape is = Circle\n");

printf("Dimesion d is = %f\n", d);

printf("Axis = yy\n");

printf("Moment of Inertia is: %0.2f\n",Iyy);

}

break;

default :

printf("Invalid input..!. Available options to select are R, H, C\n");

break;

}

return 0;

}


--------------------------------------------------------------------------------------------------------------------------------------

Here i have attached the output of the program as a screen shot....

Output: Sample run 1

-------------------------------------------------------------------------------------------------------------------------------------

please see the attached file for complete solution

Related Questions