![]() |
|
#1
|
|||
|
|||
Power Test on Resolve C++Hi All,
I have an assignment due to tomorrow but I can't figure it out. Could anyone help me about that.. Method Implementation 1 - Adding Power as a global operation Examine the file Power_Test.cpp, which is a simple test driver for global_procedure Power specified below. (Note that, 0^0 = 1.) CPP / C++ / C Code:
Write a body for the Power operation which uses the "obvious" algorithm -- repeated multiplication by the original n. This body goes into Power_Test.cpp. Test the above implementation, revising as necessary until you're convinced that this implementation of Power works. For implementation 1, the grader will look at the source code and output of Power_Test. Implementation 2 - Making Power an extension Examine the file Power_1_Test.cpp, which is the same simple test driver as above but this time for Power being the extension in abstract_instance class Natural_Power, which is in the file AI/Natural/Power.h in your lab07 directory. Write a body for the Power operation in the file CI/Natural/Power_1.h in your lab07 directory. DO NOT write the body in the test driver. Use the "obvious" algorithm (repeated multiplication). This should be very straightforward, it is almost a cut and paste from implementation 1! Test Natural_Power_1::Power using Power_1_Test.cpp as the test driver. Revise the operation body for Power until you're convinced that it works. The grader will look at the source code of Power_1.h and the output for Power_1_Test to grade this part. Implementation 3 - Making Power more efficient Copy Power_1_Test.cpp to Power_2_Test.cpp, and make the new test driver use a new implementation of Power simply by replacing ALL occurrences of Power_1, in Power_2_Test.cpp, with Power_2. Provide a new body for the Power operation in the file CI/Natural/Power_2.h in your lab07 directory. This time use the more efficient and non-obvious "fast powering" method discussed in class. Test Natural_Power_2::Power using Power_2_Test.cpp as the test driver and revising the operation body as necessary until you're convinced that this implementation of Power also works. The grader will look at the source code of Power_2.h and the output for Power_2_Test to grade implementation 3. That's the assignment. |
|||
|
#2
|
||||
|
||||
Re: Power Test on Resolve C++I don't know if this is what you're looking for, but it may help you get started:
CPP / C++ / C Code:
Output: Code:
It doesn't gracefully handle storage overflow, so there is still much more to do to make it "worthy." MxB |
|
#3
|
|||
|
|||
Re: Power Test on Resolve C++What about recursion? Could you give me an example of that too?
|
|
#4
|
|||
|
|||
Re: Power Test on Resolve C++Quote:
CPP / C++ / C Code:
A run: Code:
Regards, Dave |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trinary operator | gagless12 | C++ Forum | 5 | 06-Jun-2008 08:42 |
| Quick test whether a number is a power of two | mikhail | C Programming Language | 5 | 14-Feb-2008 08:38 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
| CSS Layout question | oihjk | Web Design Forum | 3 | 28-May-2003 12:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The