943,498 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10998
  • C++ RSS
Aug 13th, 2004
0

C++ Macros - help please

Expand Post »
I need help solving two macro questions in C++.
They are:

Define a macro PANIC that expands to code that uses coutÂ* to print the word PANIC and then calls a function quit (with no argumentsÂ*).

I think the answer is

#define PANIC;
cout <<quit();

but the compiler gives me errors.
My second question is:

Define a macro PLUS1 that accepts a valueÂ* as a parameterÂ* and produces an expressionÂ* representing 1 more than the valueÂ*.

My wrong answer was

#define PLUS1 (x)
PLUS1+1

If you know the answer, please tell me - also explain how you got the answer.

Thanks!
C++
Similar Threads
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Aug 13th, 2004
0

Re: C++ Macros - help please

ur first question is somewhat confusing. but i give my idea.

#define PANIC (cout<<"panic";quit())

the second question answer is:

#define PLUS1(x) (x+1)

still if u have any queries. write me to bvvkrishna@rediffmail.com
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bvvkrishna is offline Offline
4 posts
since Aug 2004
Aug 14th, 2004
0

Re: C++ Macros - help please

That's incorrect. Can anybody else help?
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Aug 16th, 2004
0

Re: C++ Macros - help please

Hi,
the first questions answer is

#define PANIC cout<<"panic \n"<<quit()
you should not put ; (semicolan after a #define )
Now this will solve ur problem

For the second one the previous (Krishnas) answars has to work properly
it
#define PLUS1(x) (x+1)
if any more problem feel free to mail me to brnprasad630@yahoo.co.in

with regards
prasad
Reputation Points: 11
Solved Threads: 0
Newbie Poster
brnprasad630 is offline Offline
6 posts
since Aug 2004
Aug 16th, 2004
0

Re: C++ Macros - help please

When I run the first problem through the compiler, I get the message:

Wrong code assignedÂ* to PANIC. Check the function calls and don't forget semicolons.

On the second question, I get the error message:

It seems that you are lacking parentheses around the parameterÂ* supplied.

When I put a space between PLUS1 and (x), this message appears:

Wrong code assignedÂ* to PLUS1. Please revise.

Please help.

Thanks,
C++
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Aug 17th, 2004
0

Re: C++ Macros - help please

I figured it out!!! The answers are:

#define PANIC cout<<"PANIC";quit();

and:

#define PLUS1(x) ((x)+1)

Thanks for your help anyway.
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Why can't I use Pointers to point to a Enumurated Constant
Next Thread in C++ Forum Timeline: C++ Division Remainder Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC