NEED HELPim trying to compile and run but it wont let me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
im trying to get the output as shown below after the main function but it wont let me

can someone help me do the main function so that i can get the same output as shown below

[code]//file: main.cpp//
#include <string> // provides the string type (class)
#include <iostream> // provides cout, etc.
#include "linked_list.h" // provides linked_list
#include "permute_append.h" // provides permute_append
 
using namespace std;
using namespace CISP430_A5;
 
/*PERMUTE_APPEND STUB TEST*/
int main(void) {
	permute_append tester;
	tester.do_it("CAT", "MAN");
	cout << tester.get(4);
}




THE OUTPUT SHOULD LOOK LIKE 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
String 1 for this object is:
String 2 for this object is:
There is no permutation.



String 1 for this object is:
String 2 for this object is: CATMAN
The total possible permutation is 1
That is:
CATMAN

String 1 for this object is: C
String 2 for this object is: ATMAN
The total possible permutation is 1
That is:
CATMAN

String 1 for this object is: CA
String 2 for this object is: TMAN
The total possible permutation is 2
They are:
ACTMAN CATMAN

String 1 for this object is: CAT
String 2 for this object is: MAN
The total possible permutation is 6
They are:
TACMAN ATCMAN CTAMAN TCAMAN
ACTMAN CATMAN

String 1 for this object is: CATM
String 2 for this object is: AN
The total possible permutation is 24
They are:
MTACAN TMACAN AMTCAN MATCAN
TAMCAN ATMCAN CMTAAN MCTAAN
TCMAAN CTMAAN MTCAAN TMCAAN
ACMTAN CAMTAN MACTAN AMCTAN
CMATAN MCATAN TACMAN ATCMAN
CTAMAN TCAMAN ACTMAN CATMAN


String 1 for this object is: CATMA
String 2 for this object is: N
The total possible permutation is 120
They are:
AMTACN MATACN TAMACN ATMACN MTAACN TMAACN AAMTCN AAMTCN MAATCN
AMATCN AMATCN MAATCN TAAMCN ATAMCN ATAMCN TAAMCN AATMCN AATMCN
MTAACN TMAACN AMTACN MATACN TAMACN ATMACN CAMTAN ACMTAN MCATAN
CMATAN AMCTAN MACTAN TCAMAN CTAMAN ATCMAN TACMAN CATMAN ACTMAN
MTCAAN TMCAAN CMTAAN MCTAAN TCMAAN CTMAAN AMTCAN MATCAN TAMCAN
ATMCAN MTACAN TMACAN ACAMTN CAAMTN AACMTN AACMTN CAAMTN ACAMTN
MACATN AMCATN CMAATN MCAATN ACMATN CAMATN AMACTN MAACTN AAMCTN
AAMCTN MAACTN AMACTN CAMATN ACMATN MCAATN CMAATN AMCATN MACATN
TACAMN ATCAMN CTAAMN TCAAMN ACTAMN CATAMN ATACMN TAACMN AATCMN
AATCMN TAACMN ATACMN CATAMN ACTAMN TCAAMN CTAAMN ATCAMN TACAMN
ACATMN CAATMN AACTMN AACTMN CAATMN ACATMN MTACAN TMACAN AMTCAN
MATCAN TAMCAN ATMCAN CMTAAN MCTAAN TCMAAN CTMAAN MTCAAN TMCAAN
ACMTAN CAMTAN MACTAN AMCTAN CMATAN MCATAN TACMAN ATCMAN CTAMAN
TCAMAN ACTMAN CATMAN

String 1 for this object is: CATMAN
String 2 for this object is:
The total possible permutation is 720
They are:
NAMTAC ANMTAC MNATAC NMATAC AMNTAC MANTAC TNAMAC NTAMAC ATNMAC
TANMAC NATMAC ANTMAC MTNAAC TMNAAC NMTAAC MNTAAC TNMAAC NTMAAC
AMTNAC MATNAC TAMNAC ATMNAC MTANAC TMANAC ANAMTC NAAMTC AANMTC
AANMTC NAAMTC ANAMTC MANATC AMNATC NMAATC MNAATC ANMATC NAMATC
AMANTC MAANTC AAMNTC AAMNTC MAANTC AMANTC NAMATC ANMATC MNAATC
NMAATC AMNATC MANATC TANAMC ATNAMC NTAAMC TNAAMC ANTAMC NATAMC
ATANMC TAANMC AATNMC AATNMC TAANMC ATANMC NATAMC ANTAMC TNAAMC
NTAAMC ATNAMC TANAMC ANATMC NAATMC AANTMC AANTMC NAATMC ANATMC
MTANAC TMANAC AMTNAC MATNAC TAMNAC ATMNAC NMTAAC MNTAAC TNMAAC
NTMAAC MTNAAC TMNAAC ANMTAC NAMTAC MANTAC AMNTAC NMATAC MNATAC
TANMAC ATNMAC NTAMAC TNAMAC ANTMAC NATMAC AMTANC MATANC TAMANC
ATMANC MTAANC TMAANC AAMTNC AAMTNC MAATNC AMATNC AMATNC MAATNC
TAAMNC ATAMNC ATAMNC TAAMNC AATMNC AATMNC MTAANC TMAANC AMTANC
MATANC TAMANC ATMANC CNAMTA NCAMTA ACNMTA CANMTA NACMTA ANCMTA
MCNATA CMNATA NMCATA MNCATA CNMATA NCMATA AMCNTA MACNTA CAMNTA
ACMNTA MCANTA CMANTA NAMCTA ANMCTA MNACTA NMACTA AMNCTA MANCTA
TCNAMA CTNAMA NTCAMA TNCAMA CNTAMA NCTAMA ATCNMA TACNMA CATNMA
ACTNMA TCANMA CTANMA NATCMA ANTCMA TNACMA NTACMA ATNCMA TANCMA
CNATMA NCATMA ACNTMA CANTMA NACTMA ANCTMA MTCNAA TMCNAA CMTNAA
MCTNAA TCMNAA CTMNAA NMTCAA MNTCAA TNMCAA NTMCAA MTNCAA TMNCAA
CNMTAA NCMTAA MCNTAA CMNTAA NMCTAA MNCTAA TCNMAA CTNMAA NTCMAA
TNCMAA CNTMAA NCTMAA AMTCNA MATCNA TAMCNA ATMCNA MTACNA TMACNA
CAMTNA ACMTNA MCATNA CMATNA AMCTNA MACTNA TCAMNA CTAMNA ATCMNA
TACMNA CATMNA ACTMNA MTCANA TMCANA CMTANA MCTANA TCMANA CTMANA
NAMTCA ANMTCA MNATCA NMATCA AMNTCA MANTCA TNAMCA NTAMCA ATNMCA
TANMCA NATMCA ANTMCA MTNACA TMNACA NMTACA MNTACA TNMACA NTMACA
AMTNCA MATNCA TAMNCA ATMNCA MTANCA TMANCA ACNAMT CANAMT NACAM
[/code]
can anybody help me
Not without the code for permute_append class to see what info can be retrieved.
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
heres the code for permute_append.cpp and permute_append.h and it should print as the output posted above. i need all the help i can get
file:  permute_append.cpp 

[code]#include <cstdlib> // Provides size_t // included in permute_append.h
#include <sstream> // provides the << operator for string concatenation. // not using
#include <string> //provides string type //included in permute_append.h
#include "permute_append.h"
using namespace std;
namespace CISP430_A5 
{
 
	/*CONSTRUCTORS, DECONSTRUCTOR*/
		permute_append::permute_append() {
			firstString = CAT"; // x is just a default value
			secondString = "MAN "; // x is just a default value
			total = 0;
		}
	
		permute_append::permute_append(const char* first, const char* second) {
			firstString = first;
			secondString = second;
			
			total = 1; // at least one permutation
			for (int i=firstString.length(); i>0; --i) { // number of permutations is equal to factorial of the number of characters in firstString
						total *= i;
			}
			/*Turn string into linked list of chars*/
			for (int i=0; i<firstString.length(); ++i) {
						permute_me.add(firstString[i]);
			}
		}
		permute_append::permute_append(const permute_append &source) {
			firstString = source.firstString;
			secondString = source.secondString;
			total = source.total;
			permute_me = source.permute_me;
			result_list = source.result_list;
		}
		permute_append::~permute_append() {
			total = 0;
			firstString = "";
			secondString = "";
			/*so I guess we don't need to delete the linked_list object manually*/
			// delete permute_me;
			// delete result_list;
		}
	linked_list<string> permute_append::permute(linked_list<char> charList) { // permute the characters in the array (n items, n at a time)
	/*Returns a linked_list of strings, each string a permutation of the chars in charList.*/
			static linked_list<string> perms; static linked_list<char> usedChars;
			linked_list<char> character;
			for (int i = 0; i < charList.size(); ++i) {
						character = list_splice(charList, i, 1); //??? How do we pass charList to list_splice so list_splice modifies charList directly? Answer: just like I did.
						usedChars.add( character.get(0) );
						if (charList.size() == 0) perms.add( charList_join("", usedChars) ); //??? Is charList_join() working? I believe so.
						permute(charList);
						list_splice( charList, i, 0, character.get(0) );
						list_pop( usedChars );
			}
			return perms;
	}

	string permute_append::do_it() {
	// appends secondString to each permutation of firstString and stores each result in result_list
			linked_list<string> perms( permute(permute_me) ); // ??? How do you point to the returned linked_list properly?
			// string result = "";
			for (size_t i=0; i<perms.size(); ++i) {
						result_list.add(perms.get(i) + secondString);
			}
	}
	string permute_append::do_it(const char* first, const char* second) {
	// set firstString and secondString then appends secondString to each permutation of firstString and stores each result in result_list
			firstString = first; secondString = second;
			do_it();
	}

	string permute_append::get(size_t position) { // get a result
	/*Get the item at position position from result_list */
			return result_list.get(position);
	}

} 





file: permute_append.h
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
#include <cstdlib> // Provides size_t
#include <string> // provides string type (C++ class)
#include "linked_list.h" // provides linked_list
using namespace std;
 
namespace CISP430_A5 {
		
		class permute_append {
		
			public:
				/*CONSTRUCTORS, DESTRUCTOR*/
					permute_append();
					permute_append(const char* first, const char* second);
					permute_append(const permute_append &source);
					~permute_append();

					
				/*Returns a linked_list of string items, each item a permutation of the chars in the charList argument*/
				linked_list<string> permute(linked_list<char> charList); // permute the characters in charList (n items, n at a time)
				string do_it();
				// appends secondString to each permutation of firstString and stores each result in result_list
				string do_it(const char* first, const char* second);
				// set firstString and secondString then appends secondString to each permutation of firstString and stores each result in result_list
				string get(size_t position);
				/*Get the item at position position from result_list*/
 
		private:
				size_t total;
				string firstString;
				string secondString;
				linked_list<char> permute_me;
				linked_list<string> result_list;
		};
}
[/code]
Last edited on
What do you mean by "it won't let me"?

Is it failing to compile? If so, what error messages is it displaying?

Is there an error when you try and run it? If so, what is that error?

When you run it, is it behaving differently from what you expect? If so, what behaviour are you seeing? What behaviour did you expect to see?

WE CANNOT READ YOUR MIND. You have to TELL US, in detail, what the problem is, if you're serious about wanting us to help you.
yes it fails to compile
first it is giving me this error : plus it is not showing the output as posted above. need help
1
2
3
4
5
1
1>  permute_append.cpp
1>c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\permute_append.cpp(79): fatal error C1075: end of file found before the left brace '{' at 'c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\linked_list.template(129)' was matched
1>  main.cpp
1>c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\main.cpp(17): fatal error C1075: end of file found before the left brace '{' at 'c:\users\krrish\documents\visual studio 2010\projects\krishneelcad5430cisp40013f\krishneelcad5430cisp40013f\linked_list.template(129)' was matched
1>  Generating Code...

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Last edited on
Well, if it's failing to compile, of course it won't show any output! It can't compile, so there's no executable to run!

The error messages are telling you that you have a mismatch between the number of open-braces and the number of close-braces.

The error message also tells you that the open-brace for which it cannot find a matching close-brace is at line 129 of linked_list.template. However, you've chosen not to share that code with us, and we can't possibly help you any further until you change your mind.

Is there any particular reason you're being so coy with giving us the information that would help us to help you?
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
im sorry, ill post it now, and can you also help me get the output as shown above.
#include <cassert>    // Provides assert
#include <cstdlib>    // Provides NULL and size_t

namespace CISP430_A5 {

		/* CONSTRUCTORS and DESTRUCTOR */
  		template <typename Item>
		linked_list<Item>::linked_list() {
			head_ptr = NULL;
			tail_ptr = NULL;
			cursor = NULL;
			precursor = NULL; 
			many_nodes = 0;
		}
		
		template <typename Item>
		linked_list<Item>::linked_list( const linked_list& source ) { // copier

			int src_size = source.size(); // to replicate cursor position
			int many_til_end = 0; // to replicate cursor position
			int many_til_mid = 0; // to replicate cursor position
			node<Item> *src_cursor = source.cursor; // to replicate cursor position
			
			list_copy(source.head_ptr, head_ptr, tail_ptr);

		
			many_nodes = source.many_nodes;

			/*replicate the cursor position*/
			if (src_cursor != NULL) {
					while (src_cursor != NULL) {
				++many_til_end;
				src_cursor = src_cursor->link();
					}
					many_til_mid = src_size - many_til_end;
					start(); 
					for (int i=0; i<many_til_mid; ++i) {
						advance(); // DEPENDS ON VALUE OF many_nodes ABOVE
					}
					
			else {
					cursor = NULL;
					precursor = NULL;
				}
		}
		template <typename Item>
		linked_list<Item>::~linked_list() { // Destructor
			list_clear(head_ptr);
			head_ptr = tail_ptr = cursor = precursor = NULL;
			many_nodes = 0;
		}

		/* MODIFICATION MEMBER FUNCTIONS */
		template <typename Item>
		void linked_list<Item>::start() {
			if (many_nodes > 0) { // if at least one item exists
					cursor = head_ptr;
					precursor = NULL;
			}
		}

		template <typename Item>
		void linked_list<Item>::advance() {
			if (is_item()) {
					precursor = cursor;
					cursor = cursor->link();
					if ( cursor == NULL ) {
							precursor = NULL;
					}
			}
		}

		template <typename Item>
		typename linked_list<Item>::value_type linked_list<Item>::get(size_t position) {
				for (int i=0; i<=position; ++i) { 
						if (i==0)
								start();
						else
								advance();
						if (i==position) {
								return current();
						}
				}
		}

		template <typename Item>
		void linked_list<Item>::set(size_t position, const value_type& entry) {
				if (is_item()) { 
						insert(position, entry); // insert new item to list
						advance();
						remove_current(); // remove old item from list.
				}
		}

		template <typename Item>
		void linked_list<Item>::add(const value_type& entry) {
				cursor = precursor = NULL; // remove cursor
				attach_here(entry); // <<-- attaches at end when no cursor.
		}

		template <typename Item>
		void linked_list<Item>::remove(size_t position) {
				for (int i=0; i<=position; ++i) {
							if (i==0)
									start();
							else
									advance();
							if (i==position) {
									remove_current();
							}
				}
		}

		template <typename Item>
		void linked_list<Item>::insert(size_t position, const value_type& entry) {
				for (int i=0; i<=position; ++i) { 
							if (i==0)
									start();
							else
									advance();
							if (i==position) {
									insert_here(entry);
							}
				}
		}

		template <typename Item>
		void linked_list<Item>::insert_here(const value_type &entry){
				if (!is_item() &amp;&amp; !many_nodes) {
					    cursor = new node<Item>(entry);
					    head_ptr = cursor;
					    tail_ptr = cursor;
				 }
				  
				 
				 else if (is_item() &amp;&amp; cursor == head_ptr) {
					    cursor = new node<Item>( entry );
					    cursor->set_link( head_ptr );
						 head_ptr = cursor;
				 }
         
				
				 else if (!is_item() &amp;&amp; many_nodes) {
					    cursor = new node<Item>( entry );
						cursor->set_link( head_ptr );
						head_ptr = cursor;
				  }
         
				
			   else if (is_item() &amp;&amp; cursor != head_ptr) {
				       cursor = new node<Item>( entry );
				       cursor->set_link( precursor->link() );
				       precursor->set_link( cursor );
				 }
         
				 ++many_nodes; //increase the node count
	    }
		template <typename Item>
		void linked_list<Item>::attach(size_t position, const value_type& entry) {
				for (int i=0; i<=position; ++i) { 
							if (i==0)
									start();
							else
									advance();
							if (i==position) {
									attach_here(entry);
							}
				}
		}

		template <typename Item>
		void linked_list<Item>::attach_here(const value_type& entry) {

		template <typename Item>
		void linked_list<Item>::operator =(const linked_list& source) {
				if (this != &source) {
						list_clear(head_ptr);
						head_ptr = tail_ptr = cursor = precursor = NULL;
						many_nodes = 0;

						int src_size = source.size(); // to replicate cursor position
						int many_til_end = 0; // to replicate cursor position
						int many_til_mid = 0; // to replicate cursor position
						node<Item> *src_cursor = source.cursor;
						list_copy(source.head_ptr, head_ptr, tail_ptr);
						
						many_nodes = source.many_nodes;
						/*replicate the cursor position*/
						if (src_cursor != NULL) {
								while (src_cursor != NULL) {
											++many_til_end;
											src_cursor = src_cursor->link();
								}

								many_til_mid = src_size - many_til_end; 
								start(); // put this.cursor at beginning.
								for (int i=0; i<many_til_mid; ++i) {
								advance();
								}
								/* after the for loop, the new linked_list's cursor should be at the same position as the source's cursor was.*/
						}
						else {
								cursor = NULL;
								precursor = NULL;
						}
				}
		}

		/* CONSTANT MEMBER FUNCTIONS */
		template <typename Item>
		typename linked_list<Item>::value_type linked_list<Item>::current() const {
			if ( is_item() ) {
					return cursor->data();
			}
		}
 
	/*LINKED LIST TOOLS*/
	template <typename Item>
	linked_list<Item> list_splice(linked_list<Item> &input, size_t offset, size_t length) {
			/*removes as many items as specified by length from the input
			list starting from the zero-based offset. Don't try a length longer
			than the number of remaining items (yet). Input gets modified, and the return value
			is a new linked list consisting of the that were removed from input.*/
		
			linked_list<Item> spliced;
		
			for (int i=offset; i<offset+length; ++i) {
					spliced.add( input.get(i) );
					input.remove(i);
			}
			return spliced;
	}

	template <typename Item>
	linked_list<Item> list_splice(linked_list<Item> &input, size_t offset, size_t length, Item new_item) {
			/*removes as many items as specified by length from the input
			list starting from the zero-based offset.Input gets modified, and the return value
			is a new linked list consisting of the that were removed from input.
			Additionally, new_item has been put in place of the items that were removed.*/

			input.insert(offset, new_item);
			return list_splice(input, offset+1, length);
	}

	template <typename Item>
	linked_list<Item> list_splice(linked_list<Item> &input, size_t offset, size_t length, linked_list<Item> new_items) {

		
	// input.insert(offset, new_item);
	return list_splice(input, offset+1, length);
	}

	/*template prefix not needed here since the second parameter names a specific type for the linked_list*/
	string charList_join(const char* glue, linked_list<char> pieces) {
	string joined = "";
		for (int i=0; i<pieces.size(); ++i) {
					if (i==0) { //only for the first piece do we not include the glue because there are one less glues than the total pieces (one glue between each piece).
							joined += pieces.get(i); //??? How do you append a char to the string variable ???
					}
					else {
					// joined += glue + pieces.get(i); //??? Does this way work instead of the two line method below? Answer:
							joined += glue;
							joined += pieces.get(i);
					}
		}
		return joined;
	}
 
	template <typename Item>
	typename linked_list<Item>::value_type list_pop(linked_list<Item> list) {
			return (list_splice(list, list.size()-1, 1)).get(0);
	}
 
}
@MileyBoy i need help on viewing my code and help on the output of this program as posted above. pliz correct me
Last edited on
Topic archived. No new replies allowed.