Expand|Select|Wrap|Line Numbers
- program2.cpp:7: error: expected unqualified-id before 'A'
- program2.cpp:8: error: expected unqualified-id before 'B'
- program2.cpp:9: error: expected unqualified-id before 'C'
- program2.cpp:10: error: expected unqualified-id before 'D'
- program2.cpp:11: error: expected unqualified-id before 'E'
- program2.cpp:12: error: expected unqualified-id before 'F'
- program2.cpp:13: error: expected unqualified-id before 'G'
- program2.cpp:14: error: expected unqualified-id before 'H'
- program2.cpp:15: error: expected unqualified-id before 'I'
- program2.cpp:16: error: expected unqualified-id before 'J'
- program2.cpp:17: error: expected unqualified-id before 'a'
- program2.cpp:18: error: expected unqualified-id before 'b'
- program2.cpp:19: error: expected unqualified-id before 'c'
- program2.cpp:20: error: expected unqualified-id before 'd'
- program2.cpp:21: error: expected unqualified-id before 'e'
- program2.cpp:22: error: expected unqualified-id before 'f'
- program2.cpp:23: error: expected unqualified-id before 'g'
- program2.cpp:24: error: expected unqualified-id before 'h'
- program2.cpp:25: error: expected unqualified-id before 'i'
- program2.cpp:26: error: expected unqualified-id before 'j'
Expand|Select|Wrap|Line Numbers
- program2.cpp: In member function ‘char Llist::read_element()’:
- program2.cpp:83: error: ‘cin’ was not declared in this scope
- program2.cpp:87: error: ‘cout’ was not declared in this scope
- program2.cpp:87: error: ‘endl’ was not declared in this scope
- program2.cpp: In member function ‘void Llist::print()’:
- program2.cpp:103: error: ‘cout’ was not declared in this scope
- program2.cpp:103: error: ‘endl’ was not declared in this scope
- program2.cpp: At global scope:
- program2.cpp:134: error: expected class-name before ‘(’ token
- program2.cpp: In member function ‘void Llist::duplicate(Llist&)’:
- program2.cpp:235: error: ‘source’ was not declared in this scope
- program2.cpp: In member function ‘void Llist::newvigesimalnum()’:
- program2.cpp:303: error: ‘cout’ was not declared in this scope
- program2.cpp:303: error: ‘endl’ was not declared in this scope
- program2.cpp:305: error: ‘ReadBackwards’ was not declared in this scope
- program2.cpp: In member function ‘void Llist::addvigesimalnum()’:
- program2.cpp:324: error: ‘cout’ was not declared in this scope
- program2.cpp:324: error: ‘endl’ was not declared in this scope
- program2.cpp:329: error: lvalue required as left operand of assignment
- program2.cpp:331: error: lvalue required as left operand of assignment
- program2.cpp:338: error: lvalue required as left operand of assignment
- program2.cpp: In member function ‘void Llist::multiplyvigesimalnum()’:
- program2.cpp:375: error: ‘cout’ was not declared in this scope
- program2.cpp:375: error: ‘endl’ was not declared in this scope
- program2.cpp: In member function ‘void Llist::Mainmenu()’:
- program2.cpp:394: error: ‘cout’ was not declared in this scope
- program2.cpp:394: error: ‘setw’ was not declared in this scope
- program2.cpp:394: error: ‘endl’ was not declared in this scope
- program2.cpp:397: error: argument of type ‘char (Llist::)()’ does not match ‘char’
- program2.cpp:410: error: ‘exit’ was not declared in this scope
- program2.cpp: In member function ‘void Llist::Helpmenu()’:
- program2.cpp:423: error: ‘cout’ was not declared in this scope
- program2.cpp:423: error: ‘endl’ was not declared in this scope
- program2.cpp:424: error: ‘setw’ was not declared in this scope
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <iomanip>
- #undef NULL //un defines anything from a class that has the same name as one of your constants
- typedef int element;
- const int NULL = 0;
- const char sentinel = '#';
- const char 'A' = 10;
- const char 'B' = 11;
- const char 'C' = 12;
- const char 'D' = 13;
- const char 'E' = 14;
- const char 'F' = 15;
- const char 'G' = 16;
- const char 'H' = 17;
- const char 'I' = 18;
- const char 'J' = 19;
- const char 'a' = 10;
- const char 'b' = 11;
- const char 'c' = 12;
- const char 'd' = 13;
- const char 'e' = 14;
- const char 'f' = 15;
- const char 'g' = 16;
- const char 'h' = 17;
- const char 'i' = 18;
- const char 'j' = 19;
- class listnode{
- public:
- element data;
- listnode* next;
- };
- class Llist{
- private:
- listnode* head;
- listnode* tail;
- int vignum;
- public:
- void read();
- void print();
- void clean();
- void ReadBackward();
- char read_element();
- void Inserthead(element);
- void inserttail(element);
- element DeleteHead();
- void steal(Llist&);
- void append(Llist&);
- void duplicate(Llist&);
- void reverse();
- void Mergeordered(Llist&, Llist&);
- void Printinreverse();
- void Mainmenu();
- void Helpmenu();
- void addvigesimalnum();
- void newvigesimalnum();
- void multiplyvigesimalnum();
- Llist();
- ~Llist();
- };
- int main(){
- Llist L;
- L.read();
- //L.iniliatize();
- //constructor - is just a special kind of method which is a special kind of function
- //a constructor for a particalur class is called automatically when ever and object of that class is created
- //the name of the constructor is the same as the name of the class
- //LList::LList()
- //a constructor ca nhave parameters
- //a constructor cannot have a fucntional value aka a return value
- //prototypes for constructors have to be public
- }
- char Llist::read_element(){
- char char1; //integer that will be used to check and see if the users input is valid
- cin >> char1;
- while( !cin.good () ){ //while loop that if the value is not valid will ask them to input a valid answer
- cin.clear();
- cin.ignore(256, '\n');
- cout <<"you got it wrong" << endl << "should be a valid vigisal number." << endl;
- cin >> char1;
- }
- return char1;
- }
- void Llist::print(){
- //pre:conditions the native object llist is vaild
- //post: the native object llist is unchanged and its elemesnts have been displayed to the user
- listnode* temp;
- int counter;
- temp = head;
- counter = 0;
- while(temp != NULL){
- //str.size(string name) will tell the size of the string then make a for loop that goes from 0 string size set each string char = a listnode inserthead()
- cout << temp -> data << endl;
- temp = temp -> next;
- counter++;
- }
- }
- void Llist::clean(){
- //pre: native object is valid
- //post: native object LList is vaild and empty and exists listnodes were deleted and returned the the system memory pool
- //castaway node is a node that have no pointer pointing to them
- //delete operator = takes a pointer and follows it to the dynamic variable it points to and deletes it
- //delete temp;will delete the node that temp is pointing to//when a pointer is no longer to be used dangling pointer
- //dangling pointer is a pointer that used to point to a listnode but no longer does because that listnode was deleted
- listnode* temp;
- while(head != NULL){
- temp = head;
- head = temp -> next;
- delete temp;
- }
- }
- Llist::Llist(){
- //pre: none
- //post: the native object llist is now valid and its empty
- head = NULL;
- }
- Llist::~List(){
- //pre: native object Llist is valid
- //post:the native object llist is valid and empty and all of its listnodes have had there memory returned to the system memory pool
- clean();
- }
- void Llist::ReadBackward(){
- //pre and mopost are the sames as read only backwords
- char userval;
- listnode* temp;
- clean();
- //cout << "enter elemetns " << sentinel << "to stop" << endl;
- userval = read_element();
- while(userval != sentinel){
- temp = new listnode;
- temp -> data = userval;
- temp -> next = head;
- if(head == NULL)
- tail = temp;
- else;
- head = temp;userval = read_element();
- }
- }
- void Llist::Inserthead(element val){
- //pre: native object llist is valid, and val is valid
- //post: the native object llist is unchanged except it now has a new listnode at its head-end contaning val.
- listnode* temp;
- temp = new listnode;
- temp -> data = val;
- temp -> next = head;
- if ( head == NULL)
- tail = temp;
- else
- ;
- head = temp;
- }
- void Llist::inserttail(element val){
- //pre: and Post: same as insert head except the new element is inserted at the tail end of the list
- listnode* temp;
- temp = new listnode;
- temp -> data = val;
- temp -> next = NULL;
- if (head == NULL)
- head = temp;
- else{
- tail -> next =temp;
- }
- tail = temp;
- }
- element Llist::DeleteHead(){
- //pre: the native object llist is valid and non-empty
- //post: the native object is unchanged execpt the first listnode has been removed , that listnode's memory given back to the system and that listnode's data returned.
- listnode* temp;
- element val;
- temp = head;
- head = head-> next;
- val = temp -> data;
- delete temp;
- return val;
- }
- void Llist::steal(Llist & victim){
- //pre: the native object and victim llist are valid
- //post: the native object orginal have been "cleaned" the nativeobject has all the victim objects orginal listnodes and the victim object is empty
- clean();
- head = victim.head;
- tail = victim.tail;
- victim.head = NULL;
- }
- void Llist::append(Llist & donor){ //donor is the list you are taking
- //pre: the native object and donor llist s are valid
- //post: the native objeect llists are unchanged execpt the native object is now an element by element combination of its own orginal elements and the donors orginal elements and the donor object is empty
- if (head != NULL)
- tail -> next = donor.head;
- else
- head = donor.head;
- if(donor.head != NULL)
- tail = donor.tail;
- else
- ;
- donor.head = NULL;
- }
- void Llist::duplicate(Llist & soruce){
- //pre: the native object and source llist are valid
- //post: the source llist is unchanged the orginal listnodes on the native object have been cleaned and the native object is now a listnode by listnode copy of the source llist
- listnode * temp;
- clean();
- temp = source.head;
- while ( temp != NULL){
- inserttail(temp -> data);
- temp = temp -> next;
- }
- }
- void Llist::Mergeordered(Llist & second, Llist & combo){
- //pre:the native object llist is valid and in acending order
- //the second llist is valid and in ascending order and combo is a valid list
- //post: the native object and the second object are unchanged and combo is an ascendingly ordered combination of the elements from the native object and second llist
- listnode * temp1;
- listnode * temp2;
- temp1 = head;
- temp2 = second.head;
- combo.head = NULL;
- while((temp1 != NULL)&&(temp2 != NULL))// phase 1 harvest from both lists
- if ( (temp1 -> data) < (temp2 -> data)){
- combo.inserttail(temp1 -> data);
- temp1 = temp1 -> next;
- }
- else{ //temp2 -> data <= temp1->data
- combo.inserttail(temp2 -> data);
- temp2 = temp2 -> next;
- }
- //could you use copy but only copy part of the list by multiplying by a size counter to get to the correct spot in the list
- //phase 2 harvest the remaining from the native object
- while ( temp1 != NULL){
- combo.inserttail (temp1 -> data);
- temp1 = temp1 -> next;
- }
- //phase 3 harvest remaining from second list
- while(temp2 != NULL){
- combo.inserttail(temp2 -> data);
- temp2 = temp2 -> next;
- }
- }
- void Llist::Printinreverse(){
- //pre: native object llist is valid
- //post:nativeobject llist is unchanged and has had its elemtns printed out in reverseorder
- Llist helper;
- helper.duplicate(*this);
- helper.reverse();
- helper.print();
- }
- void Llist::reverse(){
- //pre: the native object llist is valid
- //post condition the native object llist is unchanged execpt all its elements are in its reverse order
- Llist helper;
- while (head != NULL)
- //*this would give you what the native object is it self
- helper.Inserthead(DeleteHead());
- steal(helper);
- }
- void Llist::newvigesimalnum(){
- //deletes the previous vigesimalnum linked list and makes it the new one
- cout << "What is the vigesimal number you would like to add?" << endl;
- cout << "Enter " << sentinel << " when you are done inputting your number." << endl;
- ReadBackward();
- Mainmenu();
- }
- void Llist::addvigesimalnum(){
- //adds to the current vigesimalnum linked list
- char usernum;
- int remainder;
- element number;
- Llist helper;
- Llist combo;
- listnode * temp1;
- listnode * temp2;
- temp1 = head;
- temp2 = helper.head;
- combo.head = NULL;
- remainder = 0;
- cout << "What is the vigesimal number you would like to add?" << endl;
- cout << "Enter " << sentinel << " when you are done inputting your number." << endl;
- helper.ReadBackward(); //should make the numbers entered go to helper and not change the native object
- while ((temp1 != NULL)&&(temp2 != NULL)){
- (temp1 -> data) % (temp2 -> data) = remainder;
- if (remainder < 20){
- (temp1 -> data) + (temp2 -> data) = number;
- combo.inserttail(number);
- //(temp1 -> data) % (temp2 -> data) = remainder;
- temp1 = temp1 -> next;
- temp2 = temp2 -> next;
- }
- else {
- (temp1 -> data) + (temp2 -> data) + remainder = number;
- combo.inserttail(number);
- //(temp1 -> data) % (temp2 -> data) = remainder;
- temp1 = temp1 -> next;
- temp2 = temp2 -> next;
- }
- }
- while (temp1 != NULL){
- combo.inserttail(temp1 -> data);
- temp1 = temp1 -> next;
- }
- //phase 3 harvest remaining from second list
- while(temp2 != NULL){
- combo.inserttail(temp2 -> data);
- temp2 = temp2 -> next;
- }
- duplicate(combo); // should change the native object to what the combo is
- }
- void Llist::multiplyvigesimalnum(){
- //multiplys the number to the current vigesimalnum linked list
- //easy way to do multiplication in the in program 2
- //take the number you are multiplying by and break it up
- //173 * 84
- //= (173*4) + (173 * 80)
- //= (173*4) + (173 * 8 * 10)
- //= (173 * 4) + (1730 * 8)
- // call the add method to add 173 to itself 4 time then add 1730 8 times and add them together
- //change read_int to read_char
- //use division and % for adding the numbers together
- Llist helper;
- cout << "What is the vigesimal number you would like to multiply by?" << endl;
- cout << "Enter " << sentinel << " when you are done inputting your number." << endl;
- helper.ReadBackward();
- // call addvigesimalnum() to find the value of the newest input number then call addvigesimalnum again the number of time the native object is
- }
- void Llist::Mainmenu(){
- //displays the vigesimal number that you currently have. then on the input you need to have something like
- //command (h for help) :
- char useranswer;
- int answer;
- answer = 0;
- cout << "Current vigesimal number is: " << setw(5) << Printinreverse() << endl;
- cout << " " << endl;
- cout << "Command (h for help): " ;
- useranswer = read_element;
- useranswer = answer;
- if ((answer == 69) || (answer == 101))
- newvigesimalnum();
- else if ((answer == 65) || (answer == 97))
- addvigesimalnum();
- else if ((answer == 77) || (answer == 109))
- multiplyvigesimalnum();
- else if ((answer == 72) || (answer == 104))
- Helpmenu();
- else if ((answer == 81) || (answer == 113))
- exit(1);
- else
- cout << "Invaild menu option (h for help)" << endl;
- Mainmenu();
- }
- void Llist::Helpmenu(){
- //displays all the options
- //e enter enter the current vigesimal number from the keyboard
- //a add add a new vigesimal number to the current vig. number
- //m multiply multiply a new vigesimal number by the current vig. number
- //h help show this help menu
- //q quit quit the program
- cout << "Valid Commands are: " << endl;
- cout << setw(20) << "e enter enter the current vigesimal number from the keyboard" << endl;
- cout << setw(20) << "a add add a new vigesimal number to the current vig. number" << endl;
- cout << setw(20) << "m multiply multiply a new vigesimal number by the current vig. number" << endl;
- cout << setw(20) << "h help show this help menu" << endl;
- cout << setw(20) << "q quit quit the program" << endl;
- Mainmenu();
- }