to get a good input

I want to get the information TO a built type from an istream...for that purpose I have overloaded operator>> and later I have made a little parser to go along the istream and get the information...but it's not working.. does anyone know the solution?.The format that I want in inside of istream function.

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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
#include <iostream>

using namespace std;

template<typename T>
class complex{
	T r;
	T i;
public:
	complex<T>():r(0),i(0){};
	complex<T>(T a):r(a),i(0){};
	complex<T>(T a,T b):r(a),i(b){};
	
	
	
	complex<T> (const complex<T>& a){		//copy constructor
		r = a.r;
		i = a.i;
	}
	
	complex<T>& operator=(const complex<T> & a){ // copy assignament;
		
		r = a.r;
		i = a.i;
		return *this;
	}
	
	const T get_r() const{		//get real part
		T a = r;
		return a;
	}
	
	const T get_i() const{		//get imaginarium part
		T a = i;
		return a;
	}
	
};
	template<typename T>
	ostream& operator<<(ostream& os,const  complex<T>& a){
		os<<"Parte real "<<a.get_r()<<" "<<"Parte imaginaria "<<a.get_i()<<endl;
		return os;
	}
template<typename T,typename N>
class Ncomplex:virtual public complex<T>{
	N z ; 
	
public:

	Ncomplex<T,N>():complex<T>(),z(0){};
	Ncomplex<T,N>(T a,N b):complex<T>(a),z(b){};
	Ncomplex<T,N>(T a,T b,N c):complex<T>(a,b),z(c){};
	
	
	const N get_z() const {
		N a = z;
		return a;
	}
	
	
};

template<typename T,typename N>
ostream& operator<<(ostream& os,const Ncomplex<T,N>& a){
	os<<" z: "<<a.get_z()<<" r: "<<a.get_r()<<" i: "<<a.get_i()<<endl;
	return os;
}



template<typename T,typename M>
class Mcomplex: virtual public complex<T>{
	
	M y;
public:
	Mcomplex<T,M>():complex<T>(),y(0){};
	Mcomplex<T,M>(T a,M b):complex<T>(a),y(b){};
	Mcomplex<T,M>(T a,T b,M c):complex<T>(a,b),y(c){};
	
	
	
	const M get_y()const{
		M a;
		a = y;
		return a;
	}
};
template<typename T,typename M>
ostream& operator<<(ostream& os,const Mcomplex<T,M>& a){
	os<<" y: "<<a.get_y()<<" r: "<<a.get_r()<<" i: "<<a.get_i()<<endl;
	return os;
}


template<typename T,typename M,typename N>
class MNcomplex: public Mcomplex<T,M>,public Ncomplex<T,N>{
	public:
	MNcomplex<T,M,N>():Mcomplex<T,M>(),Ncomplex<T,N>(){};
	MNcomplex<T,M,N>(T a,M b,N c):complex<T>(a),Mcomplex<T,M>(a,b),Ncomplex<T,N>(a,c){};
	MNcomplex<T,M,N>(T a,T b,M c,N d):complex<T>(a,b),Mcomplex<T,M>(a,b,c),Ncomplex<T,N>(a,b,d){};

	
};

template<typename T,typename M,typename N>
ostream& operator<<(ostream& os,const MNcomplex<T,M,N>& a){
	os<<" z: "<<a.get_z()<<" y: "<<a.get_y()<<" r: "<<a.get_r()<<" i: "<<a.get_i()<<endl;
	return os;
}
template<typename T,typename M,typename N>
class Vector{
	MNcomplex<T,M,N> *elem;
	int sz;
public:
	Vector():elem (new MNcomplex<T,M,N>),sz(0){};
	Vector(int a):elem ( new MNcomplex<T,M,N>[a]),sz(a){
		
		for(int i= 0;i !=sz;++i){
			MNcomplex<T,M,N> cero;
			elem[i] = cero;
		}
		
		};
	
	
	~Vector(){delete[]elem;}
	
	int get_sz() const{
		int a = sz;
		return a;
	}

};

template<typename T,typename M,typename N>
 MNcomplex<T,M,N>& operator>>(istream& is,Vector<T,M,N>& cont){
	cout<<"You can enter this amount "<<cont.get_sz()<<"of NMcomplex"<<endl;
	cout<<"You must write the NMcomplex with this format"<<endl;
	cout<<"{1,2,3,4}"<<endl;
	MNcomplex<T,M,N> trans;
	T aux,a,b;
	M auxM,c;
	N auxN,d;
	int count = cont.get_sz()-1;
	while(count>0){
	if(is>>aux&&aux=='{')
		
		while(is.get(aux)&&aux!=','){
			a = aux;
			
		}	
	if(is>>aux&&aux==',')
		while(is.get(aux)&&aux!=','){
			b = aux;
		}
	if(is>>auxM&&auxM==',')
		while(is.get(auxM)&& auxM !=','){
			c = auxM;
		}
	if(is>>auxN&&auxN==',')
		while(is.get(auxN)&& auxN !='}'){
			d = auxN;
		}
	
	count--;
	}
	return trans(a,b,c,d);
 }


int main(){

		MNcomplex<int,int,int> test(2,3,4,5);
		MNcomplex<int,int,int> test1(1,2,3);
		MNcomplex<int,int,int> test2;
		cout<<test<<test1<<test2;
		Vector<int,int,int> input(1);
		cin>>input;
		
	

	

}
 



Topic archived. No new replies allowed.