A local company, Molding Supreme, uses produces molds to cast various shapes. Ho
ID: 3845247 • Letter: A
Question
A local company, Molding Supreme, uses produces molds to cast various shapes. However, the molds become scratched after many uses and need to be replaced which costs a lot of money. Therefore the company has been researching various formulations mold materials and heat treatments to produce a material that is not too expensive and that resists scratching. You are asked to develop a program that will help the researchers analyze the data. The researchers use multiple formulations and apply various heat treatments to these formulations. The researchers need a program to determine the highest and second highest hardness for each formulation. Your program should ask the user to enter the formulation name. Next your program should ask the user how many heat treatments were used for that formulation. The number of heat treatments must be at least 3. The user should then be prompted to enter a hardness value for each of the treatments of that formulation and output the highest and second highest hardness for that formulation. Your code should use a single string object to store the name of the formulation, a while loop to check that the number of heat treatments is at least 3, a for loop to enter the hardness for each heat treatment and determine the highest hardness and second highest hardness values, a while loop to ensure that the hardness is greater than 0 and less than or equal to 11 and a do-while loop to repeat for additional formulations.
Explanation / Answer
//C++ code
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <ctype.h>
#include <math.h>
using namespace std;
int main()
{
char hasMoreFormulations;
while(true)
{
string formulationName;
cout<<" Enter the formulation name: ";
getline(cin, formulationName);
int numHeat;
cout<<"How many heat treatments were used for formulation of " << formulationName << "? ";
cin>>numHeat;
while(numHeat<3)
{
cout<<"Please enter atleast 3 number of heat treatments Enter number of heat treatments ";
cin>>numHeat;
}
double largest=0,secondLargest=0;
int i;
for(i=0;i<numHeat;i++)
{
double k;
cout<<endl<<"Enter the hardness for treatment "<<(i+1)<<" for formulation "<<formulationName<<": ";
cin>>k;
while(k<=0||k>11)
{
cout<<"Hardness is greater than 0 and less than or equal to 11 Please reenter value ";
cin>>k;
}
if(k>largest)
{
secondLargest=largest;
largest=k;
}
}
cout<<endl<<largest<<" is the highest hardness produced for "<<formulationName << " and ";
cout<<secondLargest<<" is the second highest";
cout<<endl<<"Are there more formulations(y/n)?";
cin>>hasMoreFormulations;
if(hasMoreFormulations =='n')
break;
cin.ignore();
}
return 0;
}
/*
output:
Enter the formulation name: Wolfram 342E
How many heat treatments were used for formulation of Wolfram 342E? 5
Enter the hardness for treatment 1 for formulation Wolfram 342E: 3.4
Enter the hardness for treatment 2 for formulation Wolfram 342E: 5.6
Enter the hardness for treatment 3 for formulation Wolfram 342E: 7.8
Enter the hardness for treatment 4 for formulation Wolfram 342E: 5.6
Enter the hardness for treatment 5 for formulation Wolfram 342E: 9.7
9.7 is the highest hardness produced for Wolfram 342E and 7.8 is the second highest
Are there more formulations(y/n)?y
Enter the formulation name: new formula
How many heat treatments were used for formulation of new formula? 1
Please enter atleast 3 number of heat treatments
Enter number of heat treatments
3
Enter the hardness for treatment 1 for formulation new formula: 5.4
Enter the hardness for treatment 2 for formulation new formula: 6.5
Enter the hardness for treatment 3 for formulation new formula: 4.5
6.5 is the highest hardness produced for new formula and 5.4 is the second highest
Are there more formulations(y/n)?n
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.