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

Although copper is an excellent for wiring because of its low resistivity, it is

ID: 3671993 • Letter: A

Question

Although copper is an excellent for wiring because of its low resistivity, it is expensive to use. Therefore, a metallurgist is trying to develop another alloy that has a low resistivity. The metallurgist has developed a number of alloys of varying compositions and measured the resistivity of each of these alloys.

Eventually the metallurgist would like a program to analyze data collected in a file from hundreds of alloys. However, initially you are to provide a prototype program that will ask the metallurgist how many alloys have been measured, prompt the metallurgist to enter the resistivity along with the alloy identification (consisting of letters, digits, and spaces) for each of these alloys, and determine the alloy with the lowest resistivity as well as the lowest resistivity value that was measured.

Your prototype program should robustly (repeatedly) confirm that the metallurgist entered a positive value for the number of alloys by employing a while loop. (You do not have to test that the value is a whole number) Then you should use the loop structure of your choice to enter and to identify the lowest resistivity of the set of alloys and the corresponding alloy identification, then output the lowest resistivity and corresponding alloy identification. At this time you do not have to confirm that the metallurgist entered a valid resistivity. Use string objects to store the alloy identification information.

Please note that when you use getline to store spaces into strings, you may at times need to remove a newline character from the input stream. For example suppose you have a double variable called info and a string value called title. If you wrote the following code segment

cout<<”Enter the value for info. ”
cin>>info;

cout<< “Enter the title. ”;

getline(cin,title);

cout<<”Enter the value for info. ”

When the code segment was executed the following would happen (the bold characters represent the user’s response.) which does not allow the user to enter the title because the newline character from when the user pressed enter after typing 5.5 is stored in title.

Enter the value for info 5.5

Enter the title. Enter the value for info.

One way to fix this is to skip over (or ignore) the newline character generated from the user pressing the enter key by inserting another command as follows

cout<<”Enter the value for info. ”
cin>>info;

cout<< “Enter the title. ”;

cin.ignore(1);

getline(cin,title);

cout<<”Enter the value for info. ”

Explanation / Answer

#include<iostream>

#include <stdio.h>

#include <conio.h>

using namespace std;

int main()

{

    char AlloyName[1000][20],Resistivity[1000];

    int i,number;

    int minvalue=Resistivity[0], maxalloy=-1;

    cout<<"Enter number of alloys"<<endl;

    cin>>number;

for(i=0;i<number;i++)

{

cout<<"Enter alloy name"<<endl;

cin.ignore(1);

cin>>AlloyName[i][20];

cout<<"Enter alloy resistivity"<<endl;

cin.ignore(1);

cin>>Resistivity[i];

if(Resistivity[i]<minvalue)

     {

     minvalue=Resistivity[i];

     maxalloy=i;

     }

}

cout<<"Minimum resistivity alloy"<<endl;

cout<<AlloyName[maxalloy][20]<<":"<<Resistivity[maxalloy]<<endl;

getch();

return 0;

}

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