top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

It should store the table for ASTM standards for rebars in two dimensional array.

+2 votes
341 views

This is how the table should look like upon execution.

Index   Size   Weight(lb/ft)   Diameter(in)
0   2   0.167      0.250
1   3   0.376      0.375
2   4   0.668      0.500
3   5   1.043      0.625
4   7   1.502      0.750
5   8   2.044      0.875
6   9   2.670      1.000
7   12   3.400      1.128
8   14   4.303      1.270
But instead,our program only prints the table header but not the data.. here is our program coding..

# include <iostream>
# include <stdlib.h>
# include <string>
# include <fstream>
# include <iomanip>

using namespace std;

const int row=10;
const int column=4;
int main ()
{
  string ASMT[10][4];
  int choice;



  ifstream infile;
  ifstream open;

  cout << "This program determines the total weight of rebars used in a given" 
       << " scenario. The calculation is based on ASTM <American Service for" 
      << " testing and materials> "<< endl
      << " standards" << endl;

   cout << "\nProgram Menu:"
       << "\n<1> Print ASMT table"
       << "\n<2> Read the length of rebas used from a file"
       << "\n<3> Exit" << endl;

   cout <<"Enter the number of your choice  ";
  cin >> choice;
  cout << endl;

  infile.open("ASMT.txt");

   if(choice==1){

      if(infile.fail()) {
       cout<<"File not found!" << endl;

     }   
  }

   if(choice==1)
   {
      //int s=6;
      for(int i=0;i<row;i++)
     {

      for(int j=0;i<column;i++)
        {

         infile >> ASMT[i][j];
         cout << setw(4) << ASMT[i][j] << setw(4) << " ";
        }
         cout << endl;
     }

  }

  system("pause");
  return 0;
}
posted Apr 25, 2014 by Deepak Chitragar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You simply made a mistake and did not finish modifying the nested for loop. You must change i to j in the "for part of the loop", like the code below :

for(int j=0;j<column;j++)
{

      infile >> ASMT[i][j];
      cout << setw(4) << ASMT[i][j] << setw(4) << " ";
}
answer Apr 28, 2014 by Rahul Vaidya
Similar Questions
0 votes

I can not compile

template 
int parallel_sum(const RAIter beg, const RAIter end) {
 const auto len = end-beg;
 if(len < 1000) return std::accumulate(beg, end, 0);

 const RAIter mid = beg + len/2;
 auto handle = std::async(std::launch::async, parallel_sum, mid, end);
 const int sum = parallel_sum(beg, mid);
 return sum + handle.get();
}

int main() {
 std::vector v(10000, 1);
 std::cout 

using "g++ -Wall -std=c++11", but running it I get terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1
Aborted (core dumped)

...