Problem with executing other functions in class

In the class Metode1 I made the void brug2 function to use the variables from the class A_class. For some reason it seems like it is not executing the other functions in the class. What could be the reason for 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  #include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#define Nmax 10
using namespace std;

void test(char Valgabc,char ValgGemB,char ValgGemC, char Valg1eller23, char Valg2eller3);

class Metode1;

class A_class{
	friend class Metode1;
public:

	void Indlaes();

private:
	double A[Nmax][Nmax],b[Nmax];
	int n,m;
};

/*class B{
public:
	void Indtast_b();
	void Overfoer_b();

private:
	double A[Nmax][Nmax],b[Nmax];
	int n,m;
};

class C{
public:
	void Indlaes_C();
	void Indtast_C1();
	void Indtast_C2();
	void Overfoer_C();
	void Projektion_b();

private:
	double A84[Nmax][Nmax],Q[Nmax][Nmax],R[Nmax][Nmax],A[Nmax][Nmax],b[Nmax];
	int n,m;
*/};

class Metode1{
public:
	Metode1 ():sum(0),n(0),m(0){}

	void brug2(A_class a){

		    n = a.n;
		    m = a.m;

			for(int i=0;i<n;++i){
				for(int j=0;j<m;++j){
					A[i][j]=a.A[i][j];
				}
			}


			for(int i=0;i<n;++i)b[i]=a.b[i];

	}


	void Metode1_MatrixProd();
	void Metode1_MatrixVekProd();
	void Metode1_DanTotalMatrix();
	void Metode1_Gauss();
	void Metode1_Backwardsubstitution();
	void Metode1_UdskrivVektor();
	void Kontrol_Metode1();
private:
	double A[Nmax][Nmax],M[Nmax][Nmax],AT[Nmax][Nmax],b[Nmax],W[Nmax],TM[Nmax][Nmax],FM[Nmax][Nmax],sum,x[Nmax],bpNy[Nmax];
    int n,m;
};


int main(){

	char Valgabc,ValgGemB,ValgGemC,ValgProj,Valg1eller23,Valg2eller3,ValgIgen;


	A_class objectA;
	B objectB;
	C objectC;
	Metode1 object1;

	do{
	cout<<"Vælg a,b eller c: "<<endl;
	cin>>Valgabc;

	/*if(Valgabc=='a'){
	cout<<"Du indtastede: a - dermed valgte du a): Indlæs: n, m, A og b fra datafil."<<endl;
	objectA.Indlaes();
	}
	else if(Valgabc=='b'){
		cout<<"Du indtastede: b - dermed valgte du b): Indtast: n, m, A og b."<<endl;
		objectB.Indtast_b();
	cout<<"Vil du gemme n, m, A og b?"<<endl;
	cin>>ValgGemB;
	if(ValgGemB=='j'){
		cout<<"Her udskrives n, m, A og b til en datafil"<<endl;
		objectB.Overfoer_b();
	}
	}
	else if(Valgabc=='c'){
	cout<<"Du indtastede: c - dermed valgte du c): Indlæs: A_8 far datafil. Vælg n = 4 eller 8."<<endl;

	objectC.Indlaes_C();

	cout<<"Her indtastes m(<n) og R. Efterfølgende dannes Q og A = QR beregnes."<<endl;

	objectC.Indtast_C1();

	cout<<"Her indtastes x' og t'. Efterfølgende dannes bp og e og b = bp + e"<<endl;

    objectC.Indtast_C2();

	cout<<"Vil du gemme n, m, A og b?"<<endl;
	cin>>ValgGemC;
	if(ValgGemC=='j'){

    objectC.Overfoer_C();
	}
	cout<<"Der gælder at e er projektionen af b på Null{A^T}. Vil du tjekke om projektionen giver e? "<<endl;
	cin>>ValgProj;
	if(ValgProj=='j'){
		objectC.Projektion_b();
	}
	}

	cout<<"Vælg 1: 1 eller 2: 2,3"<<endl;
    cin>>Valg1eller23;
    cout<<Valg1eller23<<endl;

	*/if(Valg1eller23=='1'){

	object1.brug2(objectA);
    object1.Metode1_MatrixProd(); //The four functions starting from this one should be executed
    object1.Metode1_MatrixVekProd();
    object1.Metode1_DanTotalMatrix();
    object1.Metode1_Gauss();

	}

	/*else if(Valg1eller23=='2'){
		cout<<"Her udføres QR-faktorisering af A ved Gram-Schmidt faktorisering."<<endl;
		cout<<"Vælg 2 eller 3"<<endl;
		cin>>Valg2eller3;

		if(Valg2eller3=='2'){


			cout<<"Her løses Rx = Q^Tb"<<endl;
		}
		else if(Valg2eller3=='3'){
		cout<<" Her minimeres f(x)"<<endl;
		cout<<"Her skal der foretages en analyse af minimeringen. Invers Hesse-matrix og antal iterationer."<<endl;
		}
	}
	cout<<"Vil du prøve igen?"<<endl;
	cin>>ValgIgen;
	}while(ValgIgen=='j');

	cout<<"Slut"<<endl;

	cout<<"Test: Længst til venstre: "<<endl;
	test('a',ValgGemB,ValgGemC,'1',Valg2eller3);
    cout<<endl;
    cout<<"Test: Længst til højre: "<<endl;
   */ test('c',ValgGemB,'j','2','2');
	return 0;
}
Last edited on
your code is too big for me to understand the logic (I am extremely sorry) but by seeing your A_class::Metode1 function I think you should try to use call by reference function...
Last edited on
closed account (48T7M4Gy)
For some reason it seems like it is not executing the other functions in the class. What could be the reason for this?

Probably because something is wrong.

But unfortunately all the mind readers and janitors are away today.

Why don't you tidy up your junk. Perhaps remove all the REM'd out stuff for a start.

Then state clearly what the problem is by explaining what is happening vs what you expect to happen.
Topic archived. No new replies allowed.