c++ - Errors within Main program using classes -


i have few errors of same type in main program. college professor not answering emails have resort asking guys. in main program have several errors similar this: "request member of non-class type." program01 testing every function in listtype.h, olisttype.h, , ulisttype.h make sure works correctly. can provide in timely fashion appreciated.

here listtype.h:

#ifndef listtype_h_included #define listtype_h_included #include <iostream>  class listtype { public:  listtype(size_t=10);  listtype(const listtype&);  virtual ~listtype();  virtual bool insert(int)=0;  virtual bool eraseall();  virtual bool erase(int)=0;  virtual bool find(int) const=0;  size_t size() const;  bool empty() const;  bool full() const;  friend std::ostream& operator << (std::ostream&, const listtype&);  const listtype& operator= (const listtype&); protected:  int *items;  size_t capacity;  size_t count; };   #endif // listtype_h_included 

here listtype.cpp:

#include "listtype.h"  listtype::listtype (size_t a) {  capacity = a;  count = 0;  items = new int [capacity]; }  listtype::listtype(const listtype& newlist) {  capacity = newlist.capacity;  count = newlist.count;  items = new int [capacity];   (size_t = 0; < count; ++i)      items[i] = newlist.items[i]; }  listtype::~listtype() {  delete [] items; }  bool listtype::eraseall() {  count = 0;  return 0; }  size_t listtype::size() const {  return (count); }  bool listtype::empty() const {  return (count == 0); }  bool listtype::full() const {  return (count == capacity); }   std::ostream& operator << (std::ostream& out, const listtype& my_list) {  if (!my_list.empty()) {   (size_t = 0; < my_list.count; ++i){         out << my_list.items[i] << ',';   }  }  return out; }  const listtype& listtype::operator= (const listtype& rightobject) {  if (this != & rightobject) {      delete [] items;      capacity = rightobject.capacity;      count = rightobject.count;       items = new int[capacity];       (size_t = 0; < count; ++i) {          items[i] = rightobject.items[i];   }  }  return *this; } 

here ulisttype.h:

#ifndef ulisttype_h_included #define ulisttype_h_included #include <iostream>  class ulisttype: public listtype {  public:  ulisttype(size_t=10);  bool insert(int);  bool erase(int);  bool find(int) const; };   #endif // ulisttype_h_included 

here ulisttype.cpp:

#include "listtype.h" #include "ulisttype.h"   ulisttype::ulisttype (size_t c): listtype(c) {}   bool ulisttype::insert(int item) {  if (full()) {      int *newitems;      capacity *=2;      newitems = new int[capacity];      (size_t =0; < count; ++i){          newitems[i] = items[i];      }      delete [] items;      items = newitems;  }  items[count++] = item;  return true; }   bool ulisttype::erase(int item) {  bool result = false;  size_t i=0;  while ( < count && items [i] != item) {      ++i;  }  if (i < count) {      items[i] = items[-- count];      result = true;  }  return result; }   bool ulisttype::find(int item) const {  size_t = 0;  while (i < count && items [i] != item) {      ++i;  }  return < count; } 

here olisttype.h:

#ifndef olisttype_h_included #define olisttype_h_included #include <iostream>  class olisttype: public listtype { public:  olisttype(size_t=10);  bool insert(int);  bool erase(int);  bool find(int) const; };   #endif // olisttype_h_included 

here olisttype.cpp:

#include "listtype.h" #include "olisttype.h"  olisttype::olisttype(size_t c): listtype(c) {}   bool olisttype::insert(int item) {  size_t = count;  if (full()) {      int *newitems;      capacity *=2;      newitems = new int[capacity];      for(size_t j=0; j < count; ++j) {          newitems[j] = items[i];      }      delete [] items;      items = newitems;  }   while (i > 0 && items[i-1] > item){        items[count++] = item;      }  return true; }  bool olisttype::erase(int item) {  bool found=false;  size_t i=0, j= count-1, mid;  while (i <= j && !(found)){      mid = (i + j)/2;      if (item < items [mid])          j = mid - 1;      else if (item > items [mid])          = mid + 1;      found = items [mid] == item;  }  if (found) {      (i = mid; < count - 1; ++i) {          items [i] = items [i +1];      }       --count;  }  return found; }  bool olisttype::find (int item) const { bool found=false;  size_t i=0, j= count-1, mid;  while (i <= j && !(found)){      mid = (i + j)/2;      if (item < items [mid])          j = mid - 1;      else if (item > items [mid])          = mid + 1;      found = items [mid] == item;  }  return found; } 

here program01.cpp:

#include "listtype.h" #include "ulisttype.h" #include "olisttype.h" #include <iostream>  using namespace std;  int main() {  olisttype list[5] = {165, 16, 118, 212, 104};  ulisttype ranlist[10] = {243, 300, 154, 153, 592, 124, 195, 217, 289, 405};  ulisttype ulistassignmenttest;  olisttype olistassignmenttest;   cout << "the ordered list before operations:" << endl;  cout << list << endl << endl;   if(list.empty())                                     **<-- here error**      cout << "the list empty, therefore true.";  else      cout << "the list full or partially full, therefore false";  cout << endl << endl;   if(list.full())      cout << "the list full, therefore true.";  else      cout << "the list partially full or empty, therefore false";  cout << endl << endl;   list.insert(25);  cout << endl << endl;   cout << "the ordered list after insert:" << endl;  cout << list << endl << endl;   list.find(25);  cout << endl << endl;   list.find(30);  cout << endl << endl;   list.erase(25);  cout << endl << endl;   cout << "the ordered list after erase:" << endl;  cout << list << endl << endl;   cout << "the unordered list before operations:" << endl;  cout << ranlist << endl << endl;   if(ranlist.empty())     cout << "the list empty, therefore true.";  else      cout << "the list full or partially full, therefore false";  cout << endl << endl;   if(ranlist.full())      cout << "the list full, therefore true.";  else      cout << "the list partially full or empty, therefore false";  cout << endl << endl;   ranlist.insert(25);  cout << endl << endl;   cout << "the unordered list after insert:" << endl;  cout << ranlist << endl << endl;   ranlist.find(25);  cout << endl << endl;   ranlist.find(30);  cout << endl << endl;   ranlist.erase(25);  cout << endl << endl;   cout << "the unordered list after erase:" << endl;  cout << ranlist << endl << endl;   cout << "testing ordered list assignment operator" << endl;  olistassignmenttest = list;  cout << olistassignmenttest << endl << endl;   cout << "testing unordered list assignment operator" << endl;  ulistassignmenttest = ranlist;  cout << ulistassignmenttest << endl << endl   cout << "testing ordered list copy constructor" << endl;  olisttype olistvariable = list;  cout << olistvariable << endl << endl;   cout << "testing unordered list copy constructor" << endl;  ulisttype ulistvariable = ranlist;  cout << ulistvariable << endl << endl;   cout << "testing erase olist" << endl;  list.eraseall();  cout << "olist values now: " << list.empty() << endl << endl;   cout << "testing erase ulist" << endl;  ranlist.eraseall();  cout << endl << "ulist values now: " << ranlist.empty() << endl;   return 0; } 

olisttype list[5] = {165, 16, 118, 212, 104};  

this line declares array of 5 olisttype types. doesn't seem correct.

you want declare 1 olisttype , insert 5 values it. if not, please clarify line supposed denote.

here supposed do:

olisttype list; list.insert(165); list.insert(16); // etc... 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -