In: Computer Science
1 Program Summary
We are subcontractors for the Corellian Engineering Corportation (CEC) and we are working on one of the subsystems for the MC85 star cruiser. Our task is to model stress on a particular surface of the cruiser. Stress is defined as σ = Ld Area , where Ld is the load and Area is the area. Let’s say we are working with the metric measure system. So the load would be in kilo grams. Area would be meters. We need log into the system and enter the weight (Load) and the Area, (length x width) and calculate and display the stress on that particular area.
2 Program Behavior The program will do the following.
1: declare floating point variables, fLoad, fWidth, fLength and initialize them
2: declare a string to hold login password
3: display the message ”Stress Modeling SubSystem 0.1a”
4: display the login message ”Login ID: ”
5: get the login id from the user
6: compare it to the special code ”0a132”
7: don’t do the calculation if special code doesn’t match, also print out an error message (see below)
8: if the login id matches the special code we prompt the user for load, length and width
9: make sure that we give the user an error message if either length or width are 0, also print out an error message (see below)
10: we calculate the stress value
11: we display the stress value with accuracy of 2 decimal places.
12: make sure we always show the decimal value
Please note that I will be compiling your code on my computer and testing your code to see if it runs. use c++ language for this assignment and please do add a screenshot of all your codifications.
Please find the requested program below. Also including the screenshot of sample output and code to understand the indentation
Please provide your feedback
Thanks and Happy learning!
Sample output:
Partial code :
#include<iostream>
#include<string>
#include<iomanip>
int main()
{
//1: declare floating point variables, fLoad, fWidth, fLength and initialize them
float fLoad = 0.0f;
float fWidth = 0.0f;
float fLength = 0.0f;
//2: declare a string to hold login password
std::string strPassword;
//3: display the message "Stress Modeling SubSystem 0.1a"
std::cout << "Stress Modeling SubSystem 0.1a" << std::endl;
//4: display the login message "Login ID: "
std::cout << "Login ID: ";
//5: get the login id from the user
std::getline(std::cin, strPassword);
//6: compare it to the special code "0a132"
if (strPassword.compare("0a132"))
{
//7: don’t do the calculation if special code doesn’t match, also print out an error message
std::cout << "ERROR: Invalid login ID" << std::endl;
}
else
{
//8: if the login id matches the special code we prompt the user for load, length and width
std::cout << "Enter the load value (in kilo grams): ";
std::cin >> fLoad;
std::cout << "Enter the length value (in meters): ";
std::cin >> fLength;
std::cout << "Enter the width value (in meters): ";
std::cin >> fWidth;
//9: make sure that we give the user an error message if either length or width are 0,
// also print out an error message
if ((fLength == 0.0f) || (fWidth == 0.0f))
{
std::cout << "ERROR: Length or Breadth value cannot be zero." << std::endl;
}
else if (fLoad <= 0.0f)
{
std::cout << "ERROR: Load value should be greater than zero." << std::endl;
}
else
{
//10: we calculate the stress value
// Stress = Load * Area
// Stress = Load * length * width
//11: we display the stress value with accuracy of 2 decimal places.
//12 : make sure we always show the decimal value
std::cout << "Stress = " <<std::setprecision(2)<< fLoad * fLength * fWidth << std::endl;
}
}
return 0;
}