C++ to C# Help Please :)

Discussion in 'C#' started by slapshot6819, Feb 5, 2009.

  1. slapshot6819

    slapshot6819 New Member

    Joined:
    Feb 5, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi, just joined the forums! Seems pretty neat. Reading up on the OS and Ethical hacking section as soon as I'm done posting this :happy:

    This is actually a very simple program; it's a circular Queue. The problem is that I'm used to C++ and I am aware that I've done a TON of things wrong in my sloppy method of conversion to C#. I was wondering if somebody could give me a few general pointers about some of the mistakes I made. Of course the already-converted code would be great, but I don't expect anybody to take the time to do that hehe. I was just hoping for a few rules of thumb to help me convert it myself.

    Also, do I use the "System.Console.Writeline()" function just like "cout" in C++? I mean, if I want to write something involving a variable, would I do it like...

    Code:
    System.Console.Writeline("The day today is " << x << " and the year is " << y << ".");

    Code:
    #include <iostream>
    #include <string>
    
    
    
    class qObject
    {
    public:
        double time;
        string place;
    };
    
    class Queue
    {
    private:
        int front;
        int rear;
        qObject [] Q = new qObject[11];
    public:
        Queue();
        void Enqueue(qObject);
        void Dequeue();
        void Makeempty();
        bool IsEmpty();
        bool IsFull();
        int QueueCount();
        void ShowQueue();
    };
    
    Queue::Queue()
    {
        front = 0;
        rear = 0;
    }
    
    void Queue::Enqueue(qObject x)
    {
        if(IsFull()) {System.Console.WriteLine("FULL" << endl); return;}
        Q[rear].time = x.time;
        Q[rear].place = x.place;
        rear++;
        if(rear == 11) rear = 0;
    }
    
    void Queue::Dequeue()
    {
        if(IsEmpty()) {System.Console.WriteLine("EMPTY" << endl); return;}
        front++;
        if(front == 11) front = 0;
    }
    
    void Queue::Makeempty()
    {
        front = 0;
        rear = 0;
    }
    
    bool Queue::IsEmpty()
    {
        if(front == rear) return true;
        else return false;
    }
    
    bool Queue::IsFull()
    {
        if(front > rear && (front - rear) == 1) return true;
        else if(front < rear && (rear - front) == 10) return true;
        else return false;
    }
    
    int Queue::QueueCount()
    {
        if(rear > front) return (rear - front);
        else if(rear < front)
        {
            return (11 - front + rear);
        }
        else return 0;
    }
    
    void Queue::ShowQueue()
    {
        if(IsEmpty()) {System.Console.WriteLine("EMPTY" << endl); return;}
    
    /*
     * Insert code to write all elements in the Queue to the screen here. 
     * Left blank since I'm not sure if I'm doing it write or not with the 'System.Console.WriteLine' command
     */
    
    }
    
    
    public class Program1Queue
    {
        public static void Main()
        {
    
        }
    }

    Thanks,
    Mike
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice