Homework Help

Inheritance and Interface

Page 1 of 1

5 Replies - 682 Views - Last Post: 19 April 2009 - 02:22 PM Rate Topic: -----

#1 racso329  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 09

Homework Help

Post icon  Posted 18 April 2009 - 06:06 PM

Can someone help me understand this homework Im not sure what my teacher is asking and if someone can help me I would really appreciate it. He doesnt speak english very good. here is the link to his website.

http://www.cs.gsu.ed...n7/assign7.html

Please someone help me! Its elementary but I just dont understand maybe someone else can.

Is This A Good Question/Topic? 0
  • +

Replies To: Homework Help

#2 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 62
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Homework Help

Posted 18 April 2009 - 06:09 PM

I consider myself pretty good at programming but I have no idea what the program is supposed to do or how it's supposed to go at it. The problem is not explained clearly enough.
Was This Post Helpful? 0
  • +
  • -

#3 racso329  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 09

Re: Homework Help

Posted 18 April 2009 - 06:23 PM

View Postpapuccino1, on 18 Apr, 2009 - 05:09 PM, said:

I consider myself pretty good at programming but I have no idea what the program is supposed to do or how it's supposed to go at it. The problem is not explained clearly enough.


He has it where you can download the code on his website. If you click on it and download it and look at the code I think he wants it to be able to show or inheritance and interface. Could you look at his code?
Was This Post Helpful? 0
  • +
  • -

#4 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 62
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Homework Help

Posted 18 April 2009 - 06:51 PM

I'm sorry man I tried but I can't understand what your teacher wants the program to do.

Here's the Add class you should have:

class Add
    {
        public int Addition(int x, int y)
        {
            return x + y;
        }

        public int Subtraction(int x, int y)
        {
            return x - y;
        }
    }

This post has been edited by papuccino1: 18 April 2009 - 06:52 PM

Was This Post Helpful? 0
  • +
  • -

#5 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 942
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Homework Help

Posted 18 April 2009 - 08:44 PM

View Postpapuccino1, on 18 Apr, 2009 - 05:51 PM, said:

I'm sorry man I tried but I can't understand what your teacher wants the program to do.

Here's the Add class you should have:

class Add
    {
        public int Addition(int x, int y)
        {
            return x + y;
        }

        public int Subtraction(int x, int y)
        {
            return x - y;
        }
    }


Okay, an interface is a part of a class. It must be defined before the class like this:


interface IMyInterface
{
    void MethodName(parameters)
    {
    }
}




When you make your class, you inherit the interface like this:


interface IMyInterface
{
    void MethodName(parameters)
    {
    }
}

class MyClass : IMyInterface
{
}




To use this in code you have to do something like this:

IMyInterface objVariable = new MyClass();

objVariable.MethodName(parameters);



Interfaces can hold Methods, Properties, Events and Indexers. I hope this helps you.
Was This Post Helpful? 0
  • +
  • -

#6 racso329  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-April 09

Re: Homework Help

Posted 19 April 2009 - 02:22 PM

View PostSixOfEleven, on 18 Apr, 2009 - 07:44 PM, said:

View Postpapuccino1, on 18 Apr, 2009 - 05:51 PM, said:

I'm sorry man I tried but I can't understand what your teacher wants the program to do.

Here's the Add class you should have:

class Add
    {
        public int Addition(int x, int y)
        {
            return x + y;
        }

        public int Subtraction(int x, int y)
        {
            return x - y;
        }
    }


Okay, an interface is a part of a class. It must be defined before the class like this:


interface IMyInterface
{
    void MethodName(parameters)
    {
    }
}




When you make your class, you inherit the interface like this:


interface IMyInterface
{
    void MethodName(parameters)
    {
    }
}

class MyClass : IMyInterface
{
}




To use this in code you have to do something like this:

IMyInterface objVariable = new MyClass();

objVariable.MethodName(parameters);



Interfaces can hold Methods, Properties, Events and Indexers. I hope this helps you.

Thanks this is very helpful stuff. But I do have a question. Im not sure how to override the method addition : in the class, it override method 'addition' to 2*(a+B); define a new method sub to perform b-a;
and implement the method of interface 'mult' to perform a*b, and show the result in a messagebox

Class Add
{
public int Addition(inta, intb)
{
return a + b;
}
public in Subtraction(inta, intb)
{
return a - b;
}
}




interface Multiply
{
void mult(inta, intb)
{
return a * b;
}
}


}
class addsec : Add
{
Multiply m = new addsec();
m.mult(inta, intb);
}




Heres my interpretation of the code I hope its right
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1