Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C#

Name: Anonymous 2009-08-14 20:29

OK,

I need to make an array for an amount of rooms, the price, and address for dwellings. I have the properties in a class, but in Main I need to have the user input the amount of rooms, price, and address (3 different entries) and have the inputs go to an array. But how do I get the inputs to go to the array, while still using the 'filtering' code in their properties in the class?


I am confused beyond confused, and I'm sure you are after reading this. But if you can help, thank you.

Name: Anonymous 2009-08-14 20:31

What is "filtering code" ?

Name: Anonymous 2009-08-14 20:33

Like, in the Property for the Price, it's the IF statement saying "if price = lower than 10,000, then set price to 10000, else price = value"

Name: Anonymous 2009-08-14 20:49

>>3
So, what, you have a method for each entry?
And why are those different inputs going into the same array?

Name: Anonymous 2009-08-14 20:58

I'll try and sum it up better.

I have a class that has properties for price, address, and amount of rooms. In MAIN, the user inputs the amount of rooms, price, and address. That input has to go into an array that also accesses the properties in the Class to go through the if statements for each of the 3 classes(one is int, another is double, and 3rd is string).

The output is supposed to look like:

House 1. Rooms: #  , Price: $# , Address: 1 asdlfkj.  

and it is supposed to loop 4 times for 4 different dwellings.

I have it working, but the inputs basically don't access the properties in the class at all.

Name: Anonymous 2009-08-14 21:00

>>4

Also, I currently have 3 arrays, one for price, one for rooms, and one for address (since they are different data types).

But I'm unsure how to make the arrays/input access the properties in the Class.

Name: Anonymous 2009-08-14 21:08

>>6
Does C# not require accessor/mutator methods for the properties of the class? If it does, use them. If you don't have them, write them.

Name: Anonymous 2009-08-14 21:28

My god why does anyone teach in such a language.

Name: Anonymous 2009-08-14 21:32

>>6
You're going to flunk.

Name: Anonymous 2009-08-14 21:32

>>8

If I didn't have to, I woudln't take it

Name: Anonymous 2009-08-14 21:34

>>9

Lol most likely.

Name: Anonymous 2009-08-14 21:58

>>10
Your problem goes way beyond having to use Cocktothorpe. You have three arrays.

Name: Anonymous 2009-08-14 22:07

>>12

So what do you suggest, then?

I need to put objects of type int, double, and string into an array, have them sent to the class to check with their corresponding properties (set/get) and then back to Main to be displayed at the end.

Basically, the program asks the user for amount of rooms, price, and address, 4 times. After those 4 times, the input info is displayed like shown in >>5 .

For example, the property for 'rooms' is:
public int Rooms
        {
            set
            {
                if (value <= 1 || value >= 100)
                    rooms = 1;
                else
                    rooms = value;
            }
            get
            {
                return rooms;
            }
        }

in Main, when the user is asked to input the amount of rooms, the number is checked to the property and put into an array to be displayed at the end.

Name: Anonymous 2009-08-14 22:14

struct {
 int rooms;
 float price;
 char addr[128];
} dwellings[MAX_INPUT];
...
while(!feof(...) && i < MAX_INPUT) {
 fscanf(infile, "%d %f %127s\n",&dwellings[i].rooms,&dwellings[i].price,&dwellings[i].addr);
 i++;
}
...

Name: Anonymous 2009-08-14 22:19

>>14

Alright then.

But any idea what that would translate to in C#? lol

Name: Anonymous 2009-08-14 22:23

>>15
Are you seriously asking how a struct translates to a methodless object?

Name: Anonymous 2009-08-14 22:26

>>16

No, I'm seriously asking what '!feof', 'fscanf' , and 'infile' are.

Name: Anonymous 2009-08-14 22:31

>>17
Get the fuck out of here.

Name: Anonymous 2009-08-14 22:34

>>17
You could try opening a textbook.

Name: Anonymous 2009-08-14 22:48

I knew I wouldn't get an answer here.

Name: Anonymous 2009-08-14 22:53

>>20
This does not appear to be the case, you asked in the first place. If you had resigned to your fate of getting an answer (as you claim), you would not have asked.

Name: Anonymous 2009-08-14 22:55

>>20
You got more than you deserve, worthless leech.

Name: Anonymous 2009-08-14 23:00

>>22
Yeah man! I'm totally worthless! I serve no purpose in life but to sit here and lurk/leech/troll allllllll day.

Now, off to doing nothing, since I'm worthless.

Name: Anonymous 2009-08-14 23:00

>>10
Yeah wasn't ragging on you. The post-C C family is such shit it is stunning. I mean, I program in C when I absolutely have no other choice, but people voluntarily do this Java/C++/C# shit.

I feel sorry for you. I'd like to help but I cannot fathom why one would have an array of items meant for class variables, and since I cannot fathom it, it probably means one of us has misunderstood, but I am too busy F5ing a trap thread in /b/ to care.

Name: Anonymous 2009-08-14 23:19

>>24
That's why you're stunned. /b/ is your home.

Incidentally, have some enterprise Sepples.

#include "Types.h"

class Point {
public:
    Point() : x(0), y(0) { }
    Point(int32_t x, int32_t y) : x(x), y(y) { }

    int32_t getX() const { return x; }
    int32_t getY() const { return y; }
    void setX(int32_t nx) { x = nx; }
    void setY(int32_t ny) { y = ny; }

    Point & operator =(const Point &rhs) {
        if (this != &rhs) {
            x = rhs.x;
            y = rhs.y;
        }
        return *this;
    }
    bool operator ==(const Point &rhs) const { return (rhs.x == x && rhs.y == y); }
    bool operator !=(const Point &rhs) const { return !(*this == rhs); }
protected:
    int32_t x;
    int32_t y;
};

class Line {
public:
    Line() : a(Point()), b(Point()) { }
    Line(const Point &start, const Point &end) : a(start), b(end) { }

    void setStart(const Point &start) { a = start; }
    void setEnd(const Point &end) { b = end; }

    int32_t getLength() const { return (int32_t)(sqrt((float)((a.getX() - b.getX()) * (a.getX() - b.getX()) + (a.getY() - b.getY()) * (a.getY() - b.getY())))); }
protected:
    Point a;
    Point b;
};

class Shape {
public:
    Shape() { }
    virtual int32_t getArea() const = 0;
    virtual int32_t getPerimeter() const = 0;
};

class Square : public Shape {
public:
    Square() : length(0) { }
    Square(int32_t length) : length(length) { }

    int32_t getArea() const { return length * length; }
    int32_t getPerimeter() const { return length * 4; }
    int32_t getLength() const { return length; }
    void setLength(int32_t length) { this->length = length; }

    Square & operator =(const Square &rhs) {
        if (this != &rhs)
            length = rhs.length;
        return *this;
    }
    bool operator ==(const Square &rhs) const { return (rhs.length == length); }
    bool operator !=(const Square &rhs) const { return !(*this == rhs); }
protected:
    int32_t length;
};

class Rectangle : public Square {
public:
    Rectangle() : Square(0), width(0) { }
    Rectangle(int32_t length, int32_t width) : Square(length), width(width) { }

    int32_t getArea() const { return length * width; }
    int32_t getPerimeter() const { return length * 2 + width * 2; }
    int32_t getWidth() const { return width; }
    void setWidth(int32_t width) { this->width = width; }

    Rectangle & operator =(const Rectangle &rhs) {
        if (this != &rhs) {
            length = rhs.length;
            width = rhs.width;
        }
        return *this;
    }
    bool operator ==(const Rectangle &rhs) const { return (rhs.length == length && rhs.width == width); }
    bool operator !=(const Rectangle &rhs) const { return !(*this == rhs); }
protected:
    int32_t width;
};

Name: Anonymous 2009-08-14 23:56

How can anyone look at that and not get physically ill?

Name: Anonymous 2009-08-15 2:41

>>25
It's funny because in math, a square is a specific subset of rectangles. In backward Sepples, a rectangle is a square plus some extra stuff.

Name: Anonymous 2009-08-15 12:53

circle ellipse problem

Name: Anonymous 2009-08-15 17:05

>>27
But that's retarded.  A rectangle doesn't gain anything by being a subclass of Square, and it would only confuse any code expecting to work on squares.  They should be independent subclasses of Shape.

Name: Anonymous 2011-02-03 5:31

Name: Anonymous 2011-02-04 18:27


Don't change these.
Name: Email:
Entire Thread Thread List