473,224 Members | 1,361 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

The Sequence Class ( Data Structures)

11
Hello sir,
I'm supposed to Implement and Test the sequence Class Using a Fixed-Sized Array (Chapter 3), from Data Structures & Other objects using c++. The header file is provided, and so is a test program to check the correctness of the sequence class. I cannot figure out what the problem is and keep looking back and forth at the textbook and its not helping, can someone please please help me , i cannot figure out the errors in the implementation file.

Expand|Select|Wrap|Line Numbers
  1. // This is the Header File  sequence.h
  2. #define MAIN_SAVITCH_SEQUENCE_H
  3. #include <iostream>
  4. #include <cstdlib> // Provides size_t
  5.  
  6. namespace main_savitch_3
  7. {
  8.     class sequence
  9.     {
  10.     public:
  11.         // TYPEDEFS and MEMBER CONSTANTS
  12.         typedef double value_type;
  13.         typedef size_t size_type;
  14.         static const size_type CAPACITY = 30;
  15.         // CONSTRUCTOR
  16.         sequence( );
  17.         // MODIFICATION MEMBER FUNCTIONS
  18.         void start( );
  19.         void advance( );
  20.         void insert(const value_type& entry);
  21.         void attach(const value_type& entry);
  22.         void remove_current( );
  23.         // CONSTANT MEMBER FUNCTIONS
  24.         size_type size( ) const;
  25.         bool is_item( ) const;
  26.         value_type current( ) const;
  27.     private:
  28.         value_type data[CAPACITY];
  29.         size_type used;
  30.         size_type current_index;
  31.     };
  32. }
  33.  
  34. #endif
  35.  
  36.  
  37. // This is the implementation file which i have having problems with
  38. //i cant figure out what is wrong help please please
  39.  
  40.  
  41.  
  42. #include <iostream>
  43. #include <cassert> // Provides assert function
  44. #include "sequence.h" // With value_type defined as double
  45. using namespace std;
  46.  
  47. namespace main_savitch_3
  48. {
  49. // MODIFICATION MEMBER FUNCTIONS
  50. sequence::sequence ()
  51. {
  52. current_index = 0;
  53.  
  54. used = 0;
  55.  
  56. }
  57.  
  58. void sequence::start( )
  59. {
  60. current_index = 0;
  61.  
  62. }
  63.  
  64. void sequence::advance( )
  65. {
  66. assert (is_item());
  67. current_index++;
  68.  
  69. }
  70.  
  71. void sequence::insert(const value_type& entry)
  72. {
  73. int i;
  74. assert (is_item());
  75. const int old_used = used;
  76. for (i = used; i current_index; i--)
  77. {
  78. data[i]= data[i-1];
  79. data[current_index] = entry;
  80. used++;
  81. }
  82. assert( used == old_used - 1 );
  83. }
  84.  
  85. File Edit Options Buffers Tools C++ Help
  86. void sequence::attach(const value_type& entry)
  87. {
  88. int i;
  89. assert(size()<CAPACITY);
  90. const int old_used = used;
  91. for (i = used; i current_index; i--)
  92. {
  93. data[i] = data[i+1];
  94. data[current_index] = entry;
  95. used++;
  96. }
  97. assert( used == old_used - 1 );
  98. }
  99.  
  100. void sequence::remove_current( )
  101. {
  102. int i;
  103. assert (is_item());
  104. const int old_used = used; // added line here
  105. for (i= current_index +1; i < used -1; i++)
  106. {
  107. data[i] = data[i+1];
  108. used--;
  109. }
  110. assert( used == old_used - 1 ); // added line here
  111. }
  112.  
  113.  
  114. // CONSTANT MEMBER FUNCTIONS
  115. sequence::size_type sequence::size( ) const
  116. {
  117. return used;
  118.  
  119. }
  120.  
  121. bool sequence::is_item( ) const
  122. {
  123.  
  124. return current_index < used;
  125. }
  126.  
  127. sequence::value_type sequence::current( ) const
  128. {
  129.  
  130. return data[current_index];
  131. }
  132. }
  133.  
Im getting all sorts of warnings or c++ does not support default int, but i followed examples from the book please help meee =(
Feb 24 '08 #1
5 6566
Banfa
9,065 Expert Mod 8TB
Im getting all sorts of warnings or c++ does not support default int, but i followed examples from the book please help meee =(
If you are getting errors and warnings then you need to address them, as a tip it is not unusual for a low number of actual errors to produce a large number of warnings, (1 error for 3 pages of warning is my record I think) so examine the first one first.

If you need help with a specific warning or error or set of them then you are going to have to post them otherwise we wont know what they are.
Feb 25 '08 #2
Anan18
11
1>Compiling...
1>sequence9.cxx
1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(34) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2146: syntax error : missing ';' before identifier 'current_index'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2146: syntax error : missing ')' before identifier 'i'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2059: syntax error : ';'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2059: syntax error : ')'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(36) : error C2143: syntax error : missing ';' before '{'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Edit'

1>c:\users\mrahil\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Options'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Buffers'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Tools'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'C'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2143: syntax error : missing ';' before '++'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(46) : error C2143: syntax error : missing ';' before '{'

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(46) : error C2447: '{' : missing function header (old-style formal list?)

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(63) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(64) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(64) : warning C4018: '<' : signed/unsigned mismatch
1>Build log was saved at "file://c:\Users\Anan\Documents\Visual Studio 2005\Projects\Assignment2\Assignment2\Debug\BuildL og.htm"
1>Assignment2 - 19 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Feb 25 '08 #3
Anan18
11
and when i tried to fix some of those errors, it gave me more errors, i dunno.. please help me sir
Feb 25 '08 #4
Banfa
9,065 Expert Mod 8TB
and when i tried to fix some of those errors, it gave me more errors, i dunno.. please help me sir
That's not uncommon in code with errors, 1 error hides another one so you don't get the compile error for the second error until you have fixed the first.

Fixing errors is an iterative process,
  1. Compile code
  2. If there are no errors or warnings stop
  3. Fix some or all of the errors and warnings
  4. goto 1

Concentrate on these 3 warnings and errors to start with

Expand|Select|Wrap|Line Numbers
  1. 1>Compiling...
  2. 1>sequence9.cxx
  3. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cxx(34) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data
  4.  
  5. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cxx(35) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
  6.  
  7. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cxx(35) : error C2146: syntax error : missing ';' before identifier 'current_index'
  8.  
The first 2 are warnings because the type of member variable used is size_t but you are assign it to an int. The type of size_t is platform dependent but I guess it may be unsigned long on your platform (or long if you have 16 bit ints).

The third message, the error message is an actual mistake in you code, look at the line it references and see if you can spot any errors in it, you are missing an operator.

These errors are probably just by products of the error you just fixed
Expand|Select|Wrap|Line Numbers
  1. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2146: syntax error : missing ')' before identifier 'i'
  2.  
  3. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2059: syntax error : ';'
  4.  
  5. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : error C2059: syntax error : ')'
  6.  
  7. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(36) : error C2143: syntax error : missing ';' before '{'
  8.  
This is the next real error
Expand|Select|Wrap|Line Numbers
  1. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Edit'
  2.  
Go to the line(44) of code see if you can see something wrong with the syntax

This error then produces these by products

Expand|Select|Wrap|Line Numbers
  1. 1>c:\users\mrahil\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  2.  
  3. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Options'
  4.  
  5. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  6.  
  7. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Buffers'
  8.  
  9. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  10.  
  11. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'Tools'
  12.  
  13. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  14.  
  15. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2146: syntax error : missing ';' before identifier 'C'
  16.  
  17. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  18.  
  19. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C2143: syntax error : missing ';' before '++'
  20.  
  21. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  22.  
  23. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(46) : error C2143: syntax error : missing ';' before '{'
  24.  
  25. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(46) : error C2447: '{' : missing function header (old-style formal list?)
  26.  
Once you have fixed 3 - 5 errors it isprobably time to compile again and see what you get

The final three warnings

Expand|Select|Wrap|Line Numbers
  1. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(63) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data
  2.  
  3. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(64) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
  4.  
  5. 1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(64) : warning C4018: '<' : signed/unsigned mismatch
  6. 1>Build log was saved at "file://c:\Users\Anan\Documents\Visual Studio 2005\Projects\Assignment2\Assignment2\Debug\BuildL og.htm"
  7. 1>Assignment2 - 19 error(s), 5 warning(s)
are merely warning of your mix use of non-matching integer types. (i.e. assign a 32 bit int to a 16 bit int or comparing a sign and an unsigned integer)
Feb 25 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(34) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data

1>c:\users\anan\documents\visual studio 2005\projects\assignment2\assignment2\sequence9.cx x(35) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
These go away when you change your project properties to not report 64-bit portability issues. Visual Studio is concerned your size_t may be 64-bit (from Unix) but the 64-bit Windows size_t is still 32 bit and the int is till 32-bit.

size_t is deprecated ion C++. You should not be using it or any of the _t tyoes from C, like time_t, etc.

As with all warnings and errors. Fix the first one and rebuild. By the time you get ot the third or fourth error, the compiler is so confused the reported error is probably meaningless.
Feb 25 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Innocence | last post by:
Hi I've been considering how to optimize map data structures for a tile based Python game. However, since I'm a Python newbie I lack experience with Pythons 'exotic' data types like lists and...
3
by: Philippe C. Martin | last post by:
Hi, I am trying to figure out the traps/issues about sending data structures through a TCP/IP socket under the following circumstances: 1) there could be a different O/S on both side of the...
5
by: el_roachmeister | last post by:
For being a good web programmer, is a course on data structures important? It seems php already has built-in functions for what they teach in a data structures course. On the other hand all...
3
by: Babbit | last post by:
I'm working with a bunch of configuration data that needs to be sent over from a workstation to a server. The old method was to simply memcpy structures into a buffer and send that across, however...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
14
by: pat270881 | last post by:
hello, I have to implement a sequence class, however the header file is predefined class sequence { public: // TYPEDEFS and MEMBER CONSTANTS
6
by: Defcon2030 | last post by:
<bHey, can someone help me with this? I've been working on it for a few days now, and my head's starting to spin... </b> // FILE:ex1_imp.cxx // // // // CLASS IMPLEMENTED: sequence (see ex1.h...
13
by: jehugaleahsa | last post by:
Hello: I got tired of trying to find good implementations of collections and other data structures in C#. So, I started implementing my own. However, data structures is a wholly different...
4
by: jehugaleahsa | last post by:
Hello: When developing data structures for C#, there is an obvious performance hit when utilizing primitive types. For instance, a recent hash table implementation I wrote works exceedingly fast...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.