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

Write a c++ program that will scan through a file (will show below) for the Wire

ID: 3765231 • Letter: W

Question

Write a c++ program that will scan through a file (will show below) for the Wire Gauge a user entered. The program will then output the corresponding diameter. (Left collumn is gague, right is diameter)

File: (Left collumn is gague, right is diameter)

0    324.9
1   289.3
2   257.6
3   229.4
4   204.3
5   181.9  
6   162.0
7   144.3
8   128.5
9   114.4
10   101.9
11   90.74
12   80.81
13   71.96
14   64.08
15   57.07
16   50.82
17   45.26
18   40.30
19   35.89
20   31.96
21   28.46
22   25.35
23   22.60
24   20.10
25   17.90
26   15.94
27   14.20
28   12.64
29   11.26
30   10.03
31   8.928
32   7.950
33   7.080
34   6.305
35   5.615
36   5.000
37   4.453
38   3.965
39   3.531
40   3.145


Ex: User enters: 5

Output: 181.9

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void main()
{
   float g,n;
   string line;
   ifstream infile("myfile.txt");
   cout<<"Enter number";
   cin>>g;
  
   while (getline(infile, line)) // this does the

checking!
   {
       istringstream iss(line);
       //char c;
       if(iss>>n==g)
       {
           while (iss >> d)
           {
           //   iss>>d;
               cout<<d;
           }
       }
       // process value
   }
}

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