unknownmaster80's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Active Members
Active Posts:
80 (0.07 per day)
Joined:
06-August 11
Profile Views:
1,970
Last Active:
User is offline Jan 13 2013 06:59 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   unknownmaster80 has not set their status

Posts I've Made

  1. In Topic: Error in codes

    Posted 12 Jan 2013

    Yep! Thanks for the hints. I have added the include guards inside and it really did fix most of my errors. Now only left MAX_SIZE. But I still can't find the error..

    And what do you mean by 'Also header files should not contain code unless they are declaring template classes. '

    // Edit -- Oh..Do you mean putting all the codes besides the codes shown below from .h to .cpp? The reason being not to let other people see your codes. So I should add only e.g this inside the header file

    #include <string>
    #include "List.h"
    using namespace std;
    class Worker {
    private:
    	string name;
    	string username;
    	string password;
    	char position;
    public:
    	Worker();
    	Worker(string, string, string, char);
    	string getName();
    	string getUserName();
    	string getPassword();
    	char getPosition();
    	bool login(string, string, List<Worker>);
    };
    


    and the rest of the codes to .cpp file right?

    // I have added #define MAX_SIZE 20 in my code and it solved my MAX_SIZE error! Thanks alot for your help until now! THANKS LOADS!!! :DD
  2. In Topic: Error in codes

    Posted 12 Jan 2013

    OK! Thanks for re-arranging the errors!
    Hmm, Redefinition means that I have called 'MAX_SIZE' in another class right? But I have already deleted long ago. So I don't see any repeats. I have posted all of my codes too.,
  3. In Topic: Error in codes

    Posted 12 Jan 2013

    View PostSkydiver, on 12 January 2013 - 05:58 PM, said:

    Please list all the errors you are encountering, and start fixing them in that order. Above, you started with error #11. The errors 1-10 maybe the cause of error #11.


    Yep. As you said, errors 1-10 is caused by error #11. I'm also still trying to find for why it gave me an unknown size error when previously it was working well.. :X

    These are my all the errors

    Error	12	error C2133: 'CarList' : unknown size	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	19	1	DSA_Assignment
    Error	10	error C2133: 'WorkerList' : unknown size	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	18	1	DSA_Assignment
    Error	9	error C2228: left of '.length' must have class/struct/union	c:\users\user\dropbox\dsa_assignment\dsa_assignment\queue.h	87	1	DSA_Assignment
    Error	4	error C2244: 'List<ItemType>::add' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	35	1	DSA_Assignment
    Error	5	error C2244: 'List<ItemType>::del' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	49	1	DSA_Assignment
    Error	7	error C2244: 'List<ItemType>::get' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	60	1	DSA_Assignment
    Error	6	error C2244: 'List<ItemType>::isEmpty' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	54	1	DSA_Assignment
    Error	8	error C2244: 'List<ItemType>::length' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	65	1	DSA_Assignment
    Error	3	error C2244: 'List<ItemType>::List' : unable to match function definition to an existing declaration	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	24	1	DSA_Assignment
    Error	1	error C2370: 'MAX_SIZE' : redefinition; different storage class	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	4	1	DSA_Assignment
    Error	11	error C2512: 'List' : no appropriate default constructor available	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	18	1	DSA_Assignment
    Error	13	error C2512: 'List' : no appropriate default constructor available	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	19	1	DSA_Assignment
    Error	16	error C2662: 'List<ItemType>::add' : cannot convert 'this' pointer from 'List' to 'List<ItemType> &'	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	142	1	DSA_Assignment
    Error	17	error C2662: 'List<ItemType>::add' : cannot convert 'this' pointer from 'List' to 'List<ItemType> &'	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	144	1	DSA_Assignment
    Error	18	error C2662: 'List<ItemType>::add' : cannot convert 'this' pointer from 'List' to 'List<ItemType> &'	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	146	1	DSA_Assignment
    Error	15	error C2664: 'initCarList' : cannot convert parameter 1 from 'List' to 'List'	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	22	1	DSA_Assignment
    Error	14	error C2664: 'initWorkerList' : cannot convert parameter 1 from 'List' to 'List'	c:\users\user\dropbox\dsa_assignment\dsa_assignment\main.cpp	21	1	DSA_Assignment
    Error	2	error C2953: 'List' : class template has already been defined	c:\users\user\dropbox\dsa_assignment\dsa_assignment\list.h	18	1	DSA_Assignment
    


    Main class
    
    #include "List.h"
    #include "Worker.h"
    #include "Queue.h"
    #include "Car.h"
    #include <iostream>
    #include <string>
    
    using namespace std; 
    void initWorkerList(List<Worker>);
    void initCarList(List<Car>, Queue, Queue);
    
    int main() {
    	List<Worker> WorkerList;
    	List<Car> CarList;
    	Queue q1, q2;
    	initWorkerList(WorkerList);
    
        string username, password;
        cout << "Please enter your username: " << endl;
        getline(cin, username);
        cout << "Please enter your password: " << endl;
        getline(cin, password);
    
        Worker w;
        bool success = w.login(username,password, WorkerList);
        if(success) {
                 // code
    
        } else {
            cout << "Invalid username and/or password. \nPlease try again!";
        }
    
        system("pause");
        return 0; }
    
    void initWorkerList(List<Worker> WorkerList) {
        Worker w1 = Worker("Ben Ang", "Ben123", "pass123", 'M');
        WorkerList.add(w1);
        Worker w2 = Worker("Grace Eng", "Gr4ce", "loveGrace", 'W');
        WorkerList.add(w2);
        Worker w3 = Worker("Rebecca Xuan", "Xuanz", "Rebecca Xuan", 'W');
        WorkerList.add(w3); }
    
    void initCarList(List<Car> CarList, Queue q1, Queue q2) {
    	Car c1 = Car("SJS1006Z","Toyota", "Saloon car");
    	Car c2 = Car("SFW6666E", "hyundai", "Taxi (Saloon)");
    	Car c3 = Car("SCF1006G","Mercedes", "Large Van");
    	Car c4 = Car("SBQ1006Z", "Puma", "Saloon Car");
    
    	q1.enqueue(c1);
    	q2.enqueue(c1);
    	q2.enqueue(c3);
    	q1.enqueue(c4);
    	q1.enqueue(c1);
    	q1.enqueue(c1);
    	q1.enqueue(c1);
    	q2.enqueue(c2);
    	q2.enqueue(c2);
    }
    
    


    Worker class

    #include <string>
    #include "List.h" using namespace std; class Worker { private:
        string name;
        string username;
        string password;
        char position; public:
        Worker();
        Worker(string, string, string, char);
        string getName();
        string getUserName();
        string getPassword();
        char getPosition();
        bool login(string, string, List<Worker>); };
    
    Worker::Worker() {   }
    
    Worker::Worker(string n, string un, string pw, char p) {
        name = n;
        username = un;
        password = pw;
        position = p; }
    
    string Worker::getName() {
        return name; }
    
    string Worker::getUserName() {
        return username; }
    
    string Worker::getPassword() {
        return password; }
    
    char Worker::getPosition() {
        return position; }
    
    bool login(string username, string password, List<Worker> WorkerList) {
        string u, pw;
        for(int i =0; i<WorkerList.length(); i++) {
            Worker w = WorkerList.get(i);
            u = w.getUserName();
            pw = w.getPassword();
            if(username == u && password == pw) {
                return true;
            }
        }
        return false; }
    

    List class
    #include <iostream> using namespace std;
    
    const int MAX_SIZE = 20;
    
    template <typename ItemType> class List { private:
        ItemType itemList[MAX_SIZE];
        int size; public: 
        List();
        void add(ItemType);
        void del(int index);
        bool isEmpty();
        ItemType get(int);
        int length(); };
    
    
    template<typename ItemType> List<ItemType>::List() {
        size = 0; }
    
    template<typename ItemType> void List<ItemType>::add(ItemType item) {
        if(size < MAX_SIZE) {
            itemList[size] = item;
            size++; 
        } 
        else {
            cout << "List is full.\n";
        } }
    
    template<typename ItemType> void List<ItemType>::del(int index) {
        if(!isEmpty()) {
            if(index > 0 && index < size) {
                for(int i = index + 1; i <= size; i++) {
                    itemList[i-2] = itemList[i-1];
                }
                size--;
            }
        } else {
            cout << "List is empty.\n";
        } }
    
    template<typename ItemType> bool List<ItemType>::isEmpty() {
        return size == 0; }
    
    template<typename ItemType> ItemType List<ItemType>::get(int index) {
        if(index > 0 && index <= size) 
            return itemList[index-1]; }
    
    template<typename ItemType>
    int List<ItemType>::length() {
        return size;
    }
    


    Car Queue
    #include <string>
    #include <iostream>
    using namespace std;
    
    // use of #include guards
    #ifndef CAR_H
    #define CAR_H
    
    class Car { 
    private:
    	string vehicleNo;
    	string brand; // Toyota, Mercedes, Honda, Hyundai, etc..
    	string type; // Saloon Car, MPV, Large Van, etc..
    public:
    	Car();
    	Car(string,string,string);
    	int getCarCharge();
    	int getVacuumCharge(int);
    	int getPolishCharge(int);
    	void initCarList();
    };
    
    Car::Car() {
    }
    
    Car::Car(string vn, string b, string t) {
    	vehicleNo = vn;
    	brand = b;
    	type = t;
    }
    
    int Car::getCarCharge() {
    	int choice;
    	cin >> choice;
    
    	if (choice == 1) { // Saloon car $8
    		return 8;
    	} else if(choice == 2) { // MPV(Multi-Purpose Vehicle )/SUV(Sport utility vehicle)/MINI VAN $9
    		return 9;
    	} else if(choice == 3) { // Large van $12
    		return 12;
    	} else if(choice == 4) { // Taxi (Saloon) $4
    		return 4;
    	} else if(choice == 5) { // Taxi (MAXI CAB/MPV) $6
    		return 6;
    	} else if(choice == 0) { // Previous menu
    		return -3;
    	} else {
    		return -1;
    	}
    }
    
    int Car::getVacuumCharge(int type) {
    	
    	int bv = 5; // basic vacuum price
    	if (type == 1) { // saloon car
    		return bv + 4;
    	} else if(type == 2) { // MPV(Multi-Purpose Vehicle )/SUV(Sport utility vehicle)/MINI VAN
    		return bv + 5;
    	} else if(type == 3) { // Large van
    		return bv + 8;
    	} else if(type == 4) { // Taxi (Saloon)
    		return bv;
    	} else if(type == 5) { // Taxi (MAXI CAB/MPV)
    		return bv + 2;
    	} else {
    		return -1;
    	}
    }
    
    int Car::getPolishCharge(int type) {
    	int bp = 2; // basic polish price
    	if (type == 1) { // saloon car
    		return bp + 4;
    	} else if(type == 2) { // MPV(Multi-Purpose Vehicle )/SUV(Sport utility vehicle)/MINI VAN
    		return bp + 5;
    	} else if(type == 3) { // Large van
    		return bp + 8;
    	} else if(type == 4) { // Taxi (Saloon)
    		return bp;
    	} else if(type == 5) { // Taxi (MAXI CAB/MPV)
    		return bp + 2;
    	} else {
    		return -1;
    	}
    }
    #endif
    


    Queue class
    #include "Car.h"
    #include <string>
    #include <iostream>
    using namespace std;
    
    const int Q_MAX_SIZE = 20;
    
    class Queue {
    private:
    	
    	int size; // size of the queue
    	Car carQueue[Q_MAX_SIZE];
    	int front, rear;
    public:
    	Queue();
    	~Queue();
    	bool isEmpty();
    	bool isFull();
    	void enqueue(Car c);
    	void dequeue(); // just dequeue the last car in the queue
    	void dequeue(Car c); // if a certain car wants to go out of the queue midway. 
    						 // Condition: Car is not in washing. Meaning is not the 1st item in the queue
    	void dequeue(int index); // same as the previous comment
    	Car getFront();
    	Car getCarQueue();
    	int length();
    };
    
    Queue::Queue() {
    	size = 0;
    	front = 0;
    	rear = Q_MAX_SIZE -1;
    }
    
    Queue::~Queue() { 
    	while(!isEmpty()) {
    		dequeue();
    	}
    }
    
    void Queue::enqueue(Car c) {
    	if (!isFull()) {
    		rear = (rear + 1) % Q_MAX_SIZE; // circular array
    		carQueue[rear] = c;
    		size++;
    	} else {
    		cout << "Queue is currently full.\n";
    	}
    }
    
    void Queue::dequeue() { 
    
    }
    
    void Queue::dequeue(int index) {
    	if(!isEmpty()) {
    		front = (front + 1) % Q_MAX_SIZE;
    		if(front != index) {
    			carQueue[index-1] = carQueue[index];
    			rear--;
    			size--;
    		} else {
    			cout << "Not allowed to dequeue the first car in the queue.\n";
    		}
    	} else {
    		cout << "There are no cars to dequeue.\n";
    	}
    }
    
    bool Queue::isEmpty() {
    	return size == 0;	
    }
    
    bool Queue::isFull() {
    	return (size == Q_MAX_SIZE);
    }
    
    Car Queue::getFront() {
    	return carQueue[front];
    }
    
    int Queue::length() {
    	return size;
    }
    
    Car Queue::getCarQueue() {
    	for (int i=0; i< carQueue.length(); i++) {
    		return carQueue[i];
    	}
    }
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

unknownmaster80 hasn't added any friends yet.

Comments

unknownmaster80 has no profile comments yet. Why not say hello?