Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ goals: using loops Please answer with exactly what I should put into the com

ID: 3799572 • Letter: C

Question

C++ goals: using loops

Please answer with exactly what I should put into the computer for the code!

Problem: 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.

Sample outputs are given below.

Output 1: What is the name of the formulation? Tungsten Carbide 451 How many heat treatments were used for formulation Tungsten Carbide 451? 5 Enter the hardness for treatment 1 of formulation Tungsten Carbide 451. 9.89 Enter the hardness for treatment 2 of formulation Tungsten Carbide 451. 8.34 Enter the hardness for treatment 3 of formulation Tungsten Carbide 451. 9.93 Enter the hardness for treatment 4 of formulation Tungsten Carbide 451. 8.99 Enter the hardness for treatment 5 of formulation Tungsten Carbide 451. 10.02 The highest hardness for Tungsten Carbide 451 was 10.02 mohs and the second highest hardness was 9.93 mohs. Are there more formulations? (y/n) n

Output 2: What is the name of the formulation? Wolfram 162 How many heat treatments were used for formulation Wolfram 162? 2 Enter the hardness for treatment 1 of formulation Wolfram 162. 10.05 Enter the hardness for treatment 2 of formulation Wolfram 162. 9.89 Enter the hardness for treatment 3 of formulation Wolfram 162. 0 The hardness must be greater than zero and less than or equal to 11! Enter the hardness for treatment 3 of formulation Wolfram 162. 10.07 Enter the hardness for treatment 4 of formulation Wolfram 162. 12.15 The hardness must be greater than zero and less than or equal to 11! Enter the hardness for treatment 4 of formulation Wolfram 162. 11.15 The hardness must be greater than zero and less than or equal to 11! Enter the hardness for treatment 4 of formulation Wolfram 162. 10.15 Enter the hardness for treatment 5 of formulation Wolfram 162. 10.23 Enter the hardness for treatment 6 of formulation Wolfram 162. 10.01 Enter the hardness for treatment 7 of formulation Wolfram 162. 10.30 The highest hardness for Wolfram 162 was 10.3 mohs and the second highest hardness was 10.23 mohs. Are there more formulations? (y/n) y What is the name of the formulation? Stabilized Saphire How many heat treatments were used for formulation Stabilized Saphire? 2 There must be at least 3 heat treatments for each formulation! How many heat treatments were used for formulation Stabilized Saphire? 5 Enter the hardness for treatment 1 of formulation Stabilized Saphire. 8.98 Enter the hardness for treatment 2 of formulation Stabilized Saphire. 9.25 Enter the hardness for treatment 3 of formulation Stabilized Saphire. 8.45 Enter the hardness for treatment 4 of formulation Stabilized Saphire. 8.23 Enter the hardness for treatment 5 of formulation Stabilized Saphire. 8.48 The highest hardness for Stabilized Saphire was 9.25 mohs and the second highest hardness was 8.98 mohs. Are there more formulations? (y/n) n

Design your program to output treatment number corresponding to the highest hardness and the second highest hardness as well as the hardness values.

Example output message for this modification is given below Treatment 2 produced the highest hardness for Stabilized Saphire of

Explanation / Answer

// C++ code
#include <iostream>
#include <stack>
#include <string>
#include <math.h>
#include <ctype.h>

using namespace std;

int main()
{
   while(true)
   {
       string name;
       cout<<"Enter the formulation name: ";
       getline(cin, name);

       int total;
       cout<<"Enter number of heat treatments: ";
       cin>>total;

       while(total<3)
       {
           cout << "Please enter atleast 3 number of heat treatments Enter number of heat treatments ";
           cin >> total;
       }

       double max1=0,max2=0;
       double value;
       for(int i=0;i<total;i++)
       {
          
           cout << "Enter the hardness for treatment " << ((i+1)) << " of formulation " << name << ": ";
           cin>>value;
           while(value<=0||value>11)
           {
               cout<<"Hardness is greater than 0 and less than or equal to 11 ";
               cout << "Enter the hardness for treatment " << ((i+1)) << " of formulation " << name << ": ";
               cin>>value;
           }
           if(value>max1)
           {
               max2=max1;
               max1=value;
           }
       }

       cout<<"The highest hardness for " << name << " was " << max1 <<" and he second highest hardness was "<<max2 << " mohs";

       char more;
       cout << " Are there more formulations?(y/n): ";
       cin >> more;

       if(more == 'n')
           break;

       cin.ignore();
   }
   return 0;
}


/*
output:

Enter the formulation name: Stabilized Saphire
Enter number of heat treatments: 4
Enter the hardness for treatment 1 of formulation Stabilized Saphire: 3.4
Enter the hardness for treatment 2 of formulation Stabilized Saphire: 5.6
Enter the hardness for treatment 3 of formulation Stabilized Saphire: 3.2
Enter the hardness for treatment 4 of formulation Stabilized Saphire: 7.8
The highest hardness for Stabilized Saphire was 7.8 and he second highest hardness was 5.6 mohs

Are there more formulations?(y/n): y

Enter the formulation name: Tungsten Carbide 451
Enter number of heat treatments: 2
Please enter atleast 3 number of heat treatments
Enter number of heat treatments
4
Enter the hardness for treatment 1 of formulation Tungsten Carbide 451: 4.5
Enter the hardness for treatment 2 of formulation Tungsten Carbide 451: 12
Hardness is greater than 0 and less than or equal to 11
Enter the hardness for treatment 2 of formulation Tungsten Carbide 451: 10
Enter the hardness for treatment 3 of formulation Tungsten Carbide 451: 1.3
Enter the hardness for treatment 4 of formulation Tungsten Carbide 451: 4.5
The highest hardness for Tungsten Carbide 451 was 10 and he second highest hardness was 4.5 mohs

Are there more formulations?(y/n): n


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote