C++ program Write a program that uses a structure called AWG_Wire for the Americ
ID: 3670356 • Letter: C
Question
C++ program
Write a program that uses a structure called AWG_Wire for the American wire gage with two fields:
int awg
float diameter
2m
1.
Create an array of wire sizes, asking the user how many to create. Check for
2m
2.
memory error.
Enter gage and diameter of EACH size. You must use the function prototype:
void Get (AWG_wire* ptr) or void Get (AWG_wire& ref)
to get the gage and diameter of each of the sizes
2m
3.
Call a function Number which returns the number of gage sizes in the array larger than a given value.
2m
4.
Call a function Number which returns the number of diameter sizes in the array larger than a given value.
You will need a function enhancement to make steps 3 and 4 work for the Number function.
American Wire Gage (AWG) sizes
gage
22
21
20
19
18
diameter (mm)
0.65
0.72
0.81
0.91
1.02
2m 5. Add a member function, called Display that will display the data (gage and diameter) for a size. Use this function to display each size of the array.
Sample output of the program
How many wires: 3
Enter gage: 22
Enter diameter: 0.65
Enter gage: 21
Enter diameter: .72
Enter gage: 20
Enter diameter: .81
Enter a gage to search: 20
There are 2 larger
Enter a diameter to search: .75
There are 1 larger
The wire sizes are:
gage: 22, diameter: 0.65 gage: 21, diameter: 0.72 gage: 20, diameter: 0.81
2m
1.
Create an array of wire sizes, asking the user how many to create. Check for
2m
2.
memory error.
Enter gage and diameter of EACH size. You must use the function prototype:
Explanation / Answer
#include<iostream>
using namespace std;
typedef struct AWG_wire AWG_wire;
struct AWG_wire
{
int awg;
float diameter;
};
int count1=0;
int count2=0;
void Get (AWG_wire* ptr)
{
int gauge;
int diameter;
cout<<"Enter the gauge to search";
cin>>gauge;
cout<<"Enter the diameter to search";
cin>>diameter;
int i=0;
int max=0;
for(i=0;i<sizeof(ptr);i++)
{
if(ptr[i].awg>gauge)
{
count1++;
}
if(ptr[i].diameter>diameter)
{
count2++;
}
}
cout<<" There are "<<count1-1<< "gauges larger";
cout<<" There are "<<count2-1<< "diameters larger";
cout<<"the wire sizes are ";
for(i=0;i<sizeof(ptr);i++)
{
cout<<" Gage"<<ptr[i].awg<<" Diameter"<<ptr[i].diameter;
}
}
int main()
{
int i=0;
int no_of_wires;
cout<<" How many wires: ";
cin>>no_of_wires;
AWG_wire wireSizes[no_of_wires];
for(i=0;i<no_of_wires;i++)
{
cout<<" Enter Gage ";
cin>>wireSizes[i].awg;
cout<<"Enter Diameter";
cin>>wireSizes[i].diameter;
}
Get(wireSizes);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.