PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Need i need a programmer
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need i need a programmer

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 15h50   #9
Shadowman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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
  Réponse avec citation
Vieux 18/10/2007, 16h38   #10
Puppet_Sock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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

  Réponse avec citation
Vieux 18/10/2007, 17h29   #11
GameboyHippo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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!

  Réponse avec citation
Vieux 18/10/2007, 21h57   #12
tragomaskhalos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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>

  Réponse avec citation
Vieux 18/10/2007, 22h28   #13
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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?
  Réponse avec citation
Vieux 18/10/2007, 23h35   #14
tragomaskhalos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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;


  Réponse avec citation
Vieux 19/10/2007, 03h06   #15
Kira Yamato
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

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

  Réponse avec citation
Vieux 23/10/2007, 06h39   #16
zohaib.shirani@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need i need a programmer

THANX every1 4.............................

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,21780 seconds with 16 queries