C++ Macros - help please

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

C++ Macros - help please

 
0
  #1
Aug 13th, 2004
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++
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 4
Reputation: bvvkrishna is an unknown quantity at this point 
Solved Threads: 0
bvvkrishna bvvkrishna is offline Offline
Newbie Poster

Re: C++ Macros - help please

 
0
  #2
Aug 13th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: C++ Macros - help please

 
0
  #3
Aug 14th, 2004
That's incorrect. Can anybody else help?
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 6
Reputation: brnprasad630 is an unknown quantity at this point 
Solved Threads: 0
brnprasad630 brnprasad630 is offline Offline
Newbie Poster

Re: C++ Macros - help please

 
0
  #4
Aug 16th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: C++ Macros - help please

 
0
  #5
Aug 16th, 2004
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++
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: C++ Macros - help please

 
0
  #6
Aug 17th, 2004
I figured it out!!! The answers are:

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

and:

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

Thanks for your help anyway.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 9904 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC