|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
zohaib.shirani@gmail.com wrote:
> On Oct 18, 4:03 pm, Nick Keighley <nick_keighley_nos...@hotmail.com> > wrote: >> On 18 Oct, 10:56, zohaib.shir...@gmail.com wrote: >> >>> i have got a quizz to [...] >> the idea of a "quiz" is for *you* to do the work >> >>> write a programm that gives the sum of all even >>> numbers between two variables x and y and then displays the sum. >>> Include both x and y in the total sum. >>> Any one here can me............ ? >> in NAPSIC (Nick's All Purpose Symbolic Instruction Code) >> >> DEFINE print_sum_evens (INTEGER x, y) >> INTEGER sum <- 0; >> >> FOR ALL i IN RANGE (x, y) >> IF is_even (i) >> sum <- sum + i >> END >> END >> >> PRINT sum >> END >> >> -- >> Nick Keighley > > Remember i am woking in C++ with complier VC..... Sorry 4 not telling > u that > Wow. You totally missed the point, didn't you. Please quit wasting your time on programming and take easier classes in the future. -- SM rot13 for email |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Oct 18, 5:56 am, zohaib.shir...@gmail.com wrote:
[do-my-homework-for-me snipped] > Any one here can me............ ? Yes. I can you. Repeat after me. Do you want fries with that? Keep saying that until it is natural. Socks |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Oct 18, 5:56 am, zohaib.shir...@gmail.com wrote:
> i have got a quizz to write a programm that gives the sum of all even > numbers between two variables x and y and then displays the sum. > Include both x and y in the total sum. > > Any one here can me............ ? Oh quit being such losers peeps. (They just don't know how to do it) Here's the answer. #include <iostream> int main{ int x; int y; char result[8]; //Get X and Y cout<<"X: "; cin>>x; cout<<"Y: "; cin>>y; //System calls that will mightiemorphicly reconfigue teh results result[0] = 0x49; result[1] = 0x20; result[2] = 0x43; result[3] = 0x48; result[4] = 0x45; result[5] = 0x41; result[6] = 0x54; result[7] = 0x00; cout<<"The result is... "<<result; return 0; } You should definantly use this code. You professor will be blown away at your advance techniques! |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On 18 Oct, 10:56, zohaib.shir...@gmail.com wrote:
> i have got a quizz to write a programm that gives the sum of all even > numbers between two variables x and y and then displays the sum. > Include both x and y in the total sum. > > Any one here can me............ ? Well the dullards in your class will doubtless furnish an algorithmic solution using something called a 'loop'. The brighter students will realise that there is an analytic solution, and write a program to calculate this directly. However, since you are in a C++ class I feel confident that your professor will settle for nothing short of a compile-time solution using metaprogramming that spits out the answer in an error message - let's face it, you can't beat a program for speed that doesn't even produce an .exe, as I'm sure you'll agree. Type the code below into a file called metasum.cpp and then eg for x=5 and y=20, compile the code like this: cl /c metasum.cpp -Dx=5 -Dy=20 The first part of the error message will give you the answer to the problem (here, 109): metasum.cpp metasum.cpp(10) : error C2079: 'ans' uses undefined struct 'the_answer_is<__formal>' with [ __formal=109 ] : If this doesn't get you an A then there's something very wrong with all of us. <code> typedef unsigned int u; template<u> struct the_answer_is; template<u a, u b, u c > struct sx { sx() { the_answer_is<(b/2+1)*(b/2)-(a/2-1)*(a/2)+c> ans; } }; template<u a, u b, u aa, u bb> struct s; template<u a, u b> struct s<a,b,0,0> : sx<a,b,0> { s() : sx<a,b,0>() {} }; template<u a, u b> struct s<a,b,0,1> : sx<a,b-1,b> { s() : sx<a,b-1,b>() {} }; template<u a, u b> struct s<a,b,1,0> : sx<a+1,b,a> { s() : sx<a+1,b,a>() {} }; template<u a, u b> struct s<a,b,1,1> : sx<a+1,b-1,a+b> { s() : sx<a+1,b-1,a+b>() {} }; template <u a, u b> struct sum : s<a, b, a%2, b%2> {}; sum<x,y> eval; </code> |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
tragomaskhalos wrote:
> On 18 Oct, 10:56, zohaib.shir...@gmail.com wrote: >> i have got a quizz to write a programm that gives the sum of all even >> numbers between two variables x and y and then displays the sum. >> Include both x and y in the total sum. >> >> Any one here can me............ ? > > Well the dullards in your class will doubtless > furnish an algorithmic solution using something > called a 'loop'. > > The brighter students will realise that there is > an analytic solution, and write a program to > calculate this directly. > > However, since you are in a C++ class I feel > confident that your professor will settle for > nothing short of a compile-time solution using > metaprogramming that spits out the answer in > an error message - let's face it, you can't beat > a program for speed that doesn't even produce > an .exe, as I'm sure you'll agree. > > Type the code below into a file called metasum.cpp > and then eg for x=5 and y=20, compile the code like > this: > cl /c metasum.cpp -Dx=5 -Dy=20 > > The first part of the error message will give > you the answer to the problem (here, 109): > > metasum.cpp > metasum.cpp(10) : error C2079: 'ans' uses > undefined struct 'the_answer_is<__formal>' > with > [ > __formal=109 > ] > : > How can the sum of even numbers be odd? |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On 18 Oct, 22:28, red floyd <no.s...@here.dude> wrote:
> tragomaskhalos wrote: > > On 18 Oct, 10:56, zohaib.shir...@gmail.com wrote: > >> i have got a quizz to write a programm that gives the sum of all even > >> numbers between two variables x and y and then displays the sum. > >> Include both x and y in the total sum. > > > metasum.cpp > > metasum.cpp(10) : error C2079: 'ans' uses > > undefined struct 'the_answer_is<__formal>' > > with > > [ > > __formal=109 > > ] > > : > > How can the sum of even numbers be odd? Note that the problem says "include both x and y in the total sum", so if either end point is odd ... Anyway I realised that that code was needlessly verbose; this does the job just as well: typedef unsigned int u; template<u> struct the_answer_is; template<u a, u b, u c > struct sx { sx() { the_answer_is<(b/2+1)*(b/2)-(a/2-1)*(a/2)+c> ans; } }; template <u a, u b> struct sum : sx<a+a%2, b-b%2, a*(a%2)+b*(b%2)> {}; sum<x,y> eval; |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
On 2007-10-18 18:35:27 -0400, tragomaskhalos
<dave.du.vergier@logicacmg.com> said: > On 18 Oct, 22:28, red floyd <no.s...@here.dude> wrote: >> tragomaskhalos wrote: >>> On 18 Oct, 10:56, zohaib.shir...@gmail.com wrote: >>>> i have got a quizz to write a programm that gives the sum of all even >>>> numbers between two variables x and y and then displays the sum. >>>> Include both x and y in the total sum. >> >>> metasum.cpp >>> metasum.cpp(10) : error C2079: 'ans' uses >>> undefined struct 'the_answer_is<__formal>' >>> with >>> [ >>> __formal=109 >>> ] >>> : >> >> How can the sum of even numbers be odd? > > Note that the problem says "include both x and y in > the total sum", so if either end point is odd ... > > Anyway I realised that that code was needlessly > verbose; this does the job just as well: > > typedef unsigned int u; > template<u> struct the_answer_is; > > template<u a, u b, u c > > struct sx { > sx() { > the_answer_is<(b/2+1)*(b/2)-(a/2-1)*(a/2)+c> > ans; > } > }; > > template <u a, u b> > struct sum : sx<a+a%2, b-b%2, a*(a%2)+b*(b%2)> {}; > > sum<x,y> eval; Nice. It didn't work on g++ v.4.0.1, but I see what you're trying to do. -- -kira |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
THANX every1 4.............................
|
|
![]() |
| Outils de la discussion | |
|
|