• 0

[Java] Class Hierarchy Design - Serious Help Needed!


Question

This one... I have NO CLUE how to even start. I hate the teacher because he doesn't want us to ask any questions to him so I'm back here requesting help.

Design a class hierarchy that allows to determine the type of result of an expression following the precedence and combination rules of the C language. The expression is to be supplied as a String using, instead of variables, the type corresponding to each one of them.

For example, assuming the following group of declarations and expression:

int a;

float b;

char c;

b= a / c + (c + 25)

the corresponding String would be supplied as:

float = int / char + (char + int)

resulting in a float.

--------------------------

*lost*

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Am I right in thinking that the type of the result of a mixed-type expression in C is simply the highest* type that appears in the expression?

(* as in float > int > char). In which case this is a simple tokem parsing and comparing problem? In which case a class hierarchy doesn't make sense, unless maybe it's going to be a complete design for a parser?

Beats me.

ps: Someone who doesn't answer questions isn't really a teacher.

Link to comment
Share on other sites

  • 0

So if i understand this correctly...

Given via user input:

int a

float b

char c

c = b + a

your program is supposed to output,

"char = float + int"

"Resulting in char"

If thats the case,

when scanning int a, create a structure like

typedef struct

{

char name;

char type[5];

}*type;

replace the contents as needed

i.e.

type * _float;

_float->type = "float";

etc

So when it comes to scanning c = b + a, you find and replace variables that are not space,+,/,*,-, etc.

When you come across 'a', do some string manipulation (concat, insert, etc) and replace it (or construct a new string) with

type_int->type;

I haven't programmed in a while, so the syntax maybe a little iffy.

this may or may not be what is wanted, so good luck.

And the teacher is correct on not wanting any questions for this project.

Unless he never wants to be asked questions, then hes just an ass!

Link to comment
Share on other sites

  • 0
I'd be scratching my head too if given that question and not allowed to ask any questions. :blink:
I don't get it either. I'm not sure what's the input/output of the program, and how is a "class hierarchy" supposed to solve the problem.

But if not allowed to ask questions I would probably go with ekw's interpretation and cross my fingers until they bleed.

Link to comment
Share on other sites

  • 0
But if not allowed to ask questions I would probably go with ekw's interpretation and cross my fingers until they bleed.

ekw's solution needs to be re-cast into Java, in which case the parsing is already there in the API, so all you need is an enum for the types, with a ranking method in the enum itself. The solution should contain some kind of attempt a a class hierarchy, since that's what's asked for. enums are classes, but would that qualify as a "class hierarchy"?

I still think it's a dumb question asked by an even dumber "teacher".

Link to comment
Share on other sites

  • 0
Design a class hierarchy that allows to determine the type of result of an expression following the precedence and combination rules of the C language. The expression is to be supplied as a String using, instead of variables, the type corresponding to each one of them.

Conciente, is that the exact wording of the original question?. Were there any other words, no matter how apparently trivial, attached to it?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.