Please Help with Code for Civil Engineering Student!

Hi All,

I am a civil engineering student, I have never done anything code related and have been dropped in at the deep end with this project really, it is the last one I will ever have to do but I am struggling with it as coding is not my strong suit to say the least!

My current code is below, I have done the best I can from what I have learnt in the lectures, but I am really struggling with getting the code to read from a .txt file. I am using Xcode on my Mac to develop it. I am trying to get it to load the contents into an 2d array. The data is a set of constants which relate to material properties that fit into equations that I have created functions for depending on the users input. The first number on each row is the defining number and is unique to that row, the rest are the relevant values. So I need it to load the data into an array and then based on what the user has input to start with either 'C' or 'D' then the number of C or D that relates to the material being tested. I have created two txt files with both lots of variables inside as C and D have the same index numbers if that makes sense. Any help you could give me is greatly appreciated, I'm sure this is dead simple for an experienced programmer!

Thanks,
Joe

C++ Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <cstdlib>
using namespace std;
void input_data(double& Wv, double& Wp, double& L, double& bw, double& bd, int& Cno);
double total_load( double Wv,  double Wp,  double bw, double bd);
double max_bending_moment( double Wt, double L);
double Bending_stress(double M , double bd, double bw);
double Design_bending_strength( double kh, double ksys, double kmod, double fmyk, double gamm);
double shear_stress(double Vd, double bw, double bd);
double design_shear_strength(double fvd, double fvk, double kmod, double kv, double ksys, double gamm);
double bearing_stress(double Fc90d, double bw, double L);
double design_bearing_strength(double Fc90k, double kmod, double ksys, double gamm);

int main()
{
	double Wv, Wp, L, bw,  bd, Wt, M, sigmyd, kh,  ksys,  kmod,  fmyk, gamm, fmyd, Vd, fvd, fvk, kv, fc90d, fc90k;
	int Cno, row, col;
	input_data(Wv, Wp, L, bw, bd, Cno);
	
    double array[12][12];
    
    ifstream inFile;
    inFile.open("data.txt");
    
    if (inFile) {
        
    cout << "Data file found, pulling in the data now...";
    
    for (col = 0; col <= 12; col++)
        {
            for (row = 0; row <= 12; row++)
            {
                inFile >> array[col][row];
                cout << array[col][row]<< endl;
            }
        }
        
    } else {
        
    cout << "Data file not found!"<<endl;
        
    }
        
    inFile.close();
    
	Wt=total_load( Wv, Wp, bw, bd);
	M = max_bending_moment(Wt, L);
	sigmyd = Bending_stress(M,bd,bw);
	cout<< "The total load on the beam is "<<Wt<< endl;
	cout<< "the maximum bending moment of the beam is "<<M<<endl;
	cout<< "the Bending stress of the beam is "<<sigmyd<<endl;
	return 0;
}

void input_data(double& Wv, double& Wp, double& L, double& bw, double& bd, int& Cno)
{
	cout<< "input the Length of the beam: "<<endl;
    cin>> L;
	cout<< "input the width of the beam: "<<endl;
    cin>> bw;
	cout<< "input the depth of the beam: "<<endl;
    cin>> bd;
	cout<< "input the Variable characteristic load: " <<endl;
    cin>> Wv;
	cout<< "input the Permanent characteristic load: "<<endl;
    cin>> Wp;
	cout<< "input the strength characteristic of the beam"<<endl;
    cin>> Cno;
}
double total_load( double Wv,  double Wp,  double bw, double bd)                                //computation of the total load on single beam
{
	return ((1.35*Wp)+(1.5*Wv))*bw*bd;
}
double max_bending_moment( double Wt, double L)                   // computing maximum bendeing moment using value of total load wt
{
	return Wt*L/8.0;
}
double Bending_stress(double M , double bd, double bw)
{
	return (M*bd/2)/(bw*pow(bd,3))/12;
}
double Design_bending_strength( double kh, double ksys, double kmod, double fmyk, double gamm)
{
	return (kh*ksys*kmod*fmyk)/gamm;
}
double shear_stress(double Vd, double bw, double bd)
{
	return (3*Vd)/(2*bw*bd);
}
double design_shear_strength(double fvd, double fvk, double kmod, double kv, double ksys, double gamm)
{
	return (fvk*kmod*kv*ksys)/gamm;
}
double bearing_stress(double Fc90d, double bw, double L)
{
	return Fc90d/(bw*L);
}
double design_bearing_strength(double Fc90k, double kmod, double ksys, double gamm)
{
	return (Fc90k*kmod*ksys)/gamm;
}


'C' Data
1
2
3
4
5
6
7
8
9
10
11
12
14 8 0,4 16 2,0 1,7 7 4.7 0.23 0.44 290 350
16 10 0,5 17 2,2 1,8 8 5.4 0.27 0.5 310 370
18 11 0,5 18 2,2 2,0 9 6.0 0.3 0.56 320 380
20 12 0,5 19 2,3 2,2 9.5 6.4 0.32 0.59 330 390
22 13 0,5 20 2,4 2,4 10 6.7 0.33 0.63 340 410
24 14 0,5 21 2,5 2,5 11 7.4 0.37 0.69 350 420
27 16 0,6 22 2,6 2,8 11.5 7.7 0.38 0.72 370 450 
30 18 0,6 23 2,7 3,0 12 8.0 0.4 0.75 380 460
35 21 0,6 25 2,8 3,4 13 8.7  0.43 0.81 400 480
40 24 0,6 26 2,9 3,8 14 9.4 0.47 0.88 420 500
45 27 0,6 27 3,1 3,8 15 10.0 0.50 0.94 440 520 
50 30 0,6 29 3,2 3,8 16 10.7 0.53 1.00 460 550


'D' Data
1
2
3
4
5
6
30 18 0,6 23 8,0 3,0 10 8.0 0.64 0.60 530 640
35 21 0,6 25 8,4 3,4 10 8.7 0.69 0.65 560 670
40 24 0,6 26 8,8 3,8 11 9.40.75 0.70 590 700
50 30 0,6 29 9,7 4,6 14 11.80.93 0.88 650 780
60 36 0,6 32 10,5 5,3 17 14.3 1.13 1.06 700 840 
70 42 0,6 34 13,5 6,0 20 16.8 1.33 1.25 900 1080
morning fella,
is the data supposed to be comma separated or not?
Seems to be randomly placed comma's in the data files.


take a look here:
http://www.cplusplus.com/forum/general/17771/


edit: in fact, remove ALL of the comma's from your data files. It appears to read in the values correctly then.

Last edited on
The commas are supposed to be full stops, not sure why they are commas? Is a space delimiter okay?

I can't get the file to read properly, are you using Xcode or Visual Basic?

Cheers,
Joe
i'm using c++ ??
Oh sorry, I meant as in a code editor, I thought Visual Basic was the MS version of Xcode? I could be wrong though....
Visual Studio 2010, but i'm not sure what that has to do with file format you are trying to read in?
Last edited on
Ah sorry I wasn't very clear, the code doesn't pull in the text file for me if I run it in Xcode on my mac, it constantly says that the file cannot be found! Any ideas? It is in the same working directory...
nope sorry. I know nothing about macs.
Try to input the full directory of where the file is
And are you compiling it as a .exe? Because I think Macs don't execute them properly
Topic archived. No new replies allowed.