read matrix 3*4 and how use constructor...check?

what wrong with this?
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
#include <iostream>
#include <fstream>

using namespace std;

struct matrix1
{
	float num;
	float denum;
};

struct matrix2
{
	float num;
	float denum;
};

class fraction
{
	private:
	matrix1 one[3][4];
	matrix2 two[3][4];

	public:
		void read()
		{
			ifstream data;
			
			data.open("matrix.txt");
		
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<4;j++)
			{
				data>>one[i][j].num;
				data.ignore(1,'/');
				data>>one[i][j].denum;
			}
		}

		for(int i=3;i<6;i++)
		{
			for(int j=0;j<4;j++)
			{
				data>>two[i][j].num;
				data.ignore(1,'/');
				data>>two[i][j].denum;
			}
		}
		
		data.close();

		}


	void add()
	{
		float result[3][4];
		float a,b;

		for(int i=3;i<6;i++)
		{
			for(int j=0;j<4;j++)
			{
				a=(two[i][j].denum *one[i][j].num + one[i][j].denum * two[i][j].num);
				b = (two[i][j].denum * one[i][j].denum);
				result[i][j]=a/b;
			}
		}
	}
};

int main()
{
	fraction matrx;
	
	matrx.read();
	matrx.add();

	return 0;
}
Your struct matrix1 and struct matrix2 confuse me please explain why they appear to be the same thing yet you have two of them? You never seem to have an output for your answer so how do you know anything is wrong (There is something wrong by the way)? Really think about line 67, this seems to be your issue.
Last edited on
Topic archived. No new replies allowed.