I think I have a problem.

Pages: 12
So I'm in the middle of rereading a section of Accelerated C++ regarding generic functions. I read "For generic parameters, the implementation doesn't need to worry about what to do about objects..." "The template header tells the implementation..." "The implementation will bind T to a type..." "The Implementation instantiates our code as if we had..." and as I read the words "the implementation," it sounded in my head almost as if it were.. divine. Some higher power with the ability to control anything and everything at the swiftness of my fingertips. The is all and end all. The implementation.

I need to get laid.
Last edited on
There's a lot of stuff that's implementation-defined, yeah. Good languages involve the implementation (compiler) doing a LOT of behind-the-scenes work to make your code easy to write but also very efficient, so yeah, it is pretty godly - the one thing that makes it non-godly is that the implementation is sometimes wrong.

Heh, godly compilers. Clang, and thou shall receive.
Last edited on
Yeah man. It's just really weird how it's sort of taken on human-like qualities in my mind. I've been doing this for far too long, haha!
Other way around for me. I see the world in object-oriented relationships.
I also see it like that. It began a few months after I first got into C/++ (i was like, 13 years old at the time) and suddenly I had the mental tools to solve all sorts of problems and follow logical reasoning I couldn't before. that was nearly 5 years ago. When it really comes down to it, i give almost complete credit for my academic success to programming. The cool thing about programming is it's not just about writing programs, it's how you think broken down into instructions. There's no better way to exercise your mind. Merely being exposed to it has been such a massive benefit to me.
I think it would be an absolutely wonderful idea to have an elective class in grades 6-8 that offered an intro to programming.
closed account (1yR4jE8b)
One day, you'll look at code and all you'll see is "blonde", "brunnette", "red dress".
Normally I look at code and say "low level", "poor style", or "I wish I could code like that".
can someone help me 2 my ass. please i need it this day please........


ASAP


write a program that will output the sum of the even & odd numbers from int A to B. prompt the user to input the 1st &2nd numbers A &b & output the sum of even & odd nos. from A to B. if the user input A which is more than b . dispaly an error message

EXPECTED INPUT
ENTER A : 1
ENTER B: 10
EXPECTED OUTPUT
sum of even:2 4 6 8 10 :30
sum of odd: 1 3 5 7 9 15: 25
THANK YOU SO much please help ineed in this day
camillevalerio wrote:
can someone help me 2 my ass.

It's hard to insert a good gay joke into this one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

int main()
{
	int a, b, sumOfEven=0, sumOfOdd=0;

	std::cout << "ENTER A: ";
	std::cin >> a;
	std::cout << "ENTER B: ";
	std::cin >> b;
	std::cout << "sum of even: ";

	for (int i=a; i<=b; ++i)
		if (i%2 == 0)
		{
			std::cout << i << ' ';
			sumOfEven += i;
		}

	std::cout << ": " << sumOfEven << "\nsum of odd: ";

	for (int i=a; i<=b; ++i)
		if (i%2 != 0)
		{
			std::cout << i << ' ';
			sumOfOdd += i;
		}

	std::cout << ": " << sumOfOdd << '\n' << std::endl;
}

@Catfish2, I like mine better, even though it's painfully obvious. :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

void outputresults(int a, int b)
{
	int output1[4] = {154 >> 1, (64 ^ (9 >> 3)) | 72, (38 << 1) | 66, 78 & 68};
	int output2[5] = {output1[3] | 66, 170 >> 1, output1[3]-1, (65 | 75)};
	
	for(int i = 0; i < 4; ++i)
		cout << (char)output1[i];
	cout << " ";
	for(int i = 0; i < 5; ++i)
		cout << (char)output2[i];
		
}

int main()
{
	int a, b;
	cout << "Enter A: ";
	cin >> a;
	cout << "\nEnter B: "; 
	cin >> b;

	while(1)
		outputresults(a, b);
	system("PAUSE");
}
Last edited on
My brain keeps trying to use keyboard shortcuts (^Z for undo, ^C^V for copy/paste, etc.) IRL. I've accidentally referred to throwing things away as deleting them. I represent sentences like this: "(represent I (like (this '(verb subject object)) sentences))". In maths, I have to convert expressions like "x + iy" into the form "(+ x (* iy))". I can't differentiate between code and data. I can't do anything that has side-effects: if someone asks me to do something, unless they watch me do it, there's no way I can prove that I did it. I often can't name my actions. Sometimes, I'll do something, and then before I finish doing it, I have to do it again and again. I have become purely functional. Come here. Let me compute your fixed point.

Okay, I made the last ones up, but the first two are true.
May your garbage be collected!
closed account (D80DSL3A)
+1 darkestfright for the awesome line from The Matrix.

EDIT: Welcome back Thumper.
I too have been recently bitten by an arduino bug.
Last edited on
@fun2code
Yeah, the things killing me. I keep buying more and more electronics parts and i'm just sitting here watching my wallet get thinner and thinner. You can't just buy an Arduino and be done with it. You buy an arduino, then you buy $80 in electronic components, a breadboard, and jumpers. Then you want to do a real project so you buy an RFID reader and various ribbon cables and headers. Then you realize you want to actually implement this project so you go buy bulk copper clad boards off of ebay, stop by lowes and pick up a gallon of muriatic acid, and spend wayy to much money on glossy printing paper. After you waste half of that paper you just bought failing to toner transfer to copper clad board, you finally get it right. Then you go to etch it and see that it takes way too long to etch just in that solution. So you go to buy $100 in plexiglass from lowes and $50 in acrylic welding solutions from amazon, and a heater and bubbler from a pet store so that you can build a PCB etching tank.
Finally, only when you're dead broke, do you finish the project and have RFID door locks for your car.
I think it was worth it. :)
closed account (D80DSL3A)
@Thumper. I haven't gotten that deep into it yet (about 1 week). I've only toasted one $4 chip so far...

I'm impressed with the programming language for it. It is said to be "c like" but I find it is identical to C++ in most every way! The limitations I have found so far:
1) No template classes.
2) No dynamic memory allocation ( new/delete ) not available.
3) No STL or other standard library functionality, but many common functions are implemented in their own headers.

I have found that I can use abstract classes, virtual functions, etc.. and it all compiles and works great!
I will need to get used to the idea of programming for an environment in which memory is precious, however.

32K flash memory limit for the program?
1KB SRAM limit for program variables?

What is UP with these memory limits? Is it still 1970?

They point out that storing v-tables in that flash memory space can be wasteful. Perhaps more basic programming methods will be best here.

I now have a nice push_button class which turns an ordinary normally open contact switch into a button which retrieves and debounces its own input (responding only to stable input) and also has "push and hold to activate" and double-click functionality. The functional interface I give for it makes it very convenient to use in a program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void loop() // the "logic" loop (program running on arduino)
{
   long t_now = millis();// get the time (in millisecs since program startup)

   PB1.update( t_now );  // update the push buttons state

  int n = 1;
  if( PB1.pop(n) )// a button event has occurred 
  {
    switch(n)
    {
      case -1:// PB released : closed -> open     
      case 1:// PB pressed: open -> closed      
      case 2:// PB has been held down for tDelayHold millis.      
      case 3:// double click      
    }    
  } 
  
}

I can't think of anything else that I would want a button to do!
No end to the fun here.
Last edited on
That's because the programming language is C++.

Do I have news for you. Stop using the crappy Arduino IDE! Start using Atmel Studios. http://www.atmel.com/microsite/atmel_studio6/
Visual Studio based, sooo much easier to manage multi-file projects.

As far as I was aware, you could create template classes. I haven't ever had a reason to try it as of yet, though.

Also, it's not that it doesn't support dynamic memory allocation, it just uses the C way to do it, malloc and free.
But you can define the new and delete operators. Someone made a really nice header for all of the C++ memory allocation functions. You can throw these in your arduino library folder, include them in your project, and then you can use new and delete operators. Although, you have to be careful when dynamically allocated memory because you only have 1kb.
New.h - http://pastebin.com/04UyLiWE
New.cpp - http://pastebin.com/Kg2JPfzR

As for STL, there is a light version of the STL build for AVR chips that includes the ability to use algorithm, limits, map, queue, set, deque, pair, vectors, and several other STL containers. I can't remember where I originally found it, but i've uploaded it to my mediafire here: http://www.mediafire.com/?rchypr265b2nl62

And the Atmega328p is a very basic chip. It operates at 16MHz, it's not meant to be a powerhouse. That, and they're dirt cheap. 32K of flash memory, and 1Kb RAM is wayyy more than i'll ever use for any project i'll do with an arduino. If you want to do heavy operations you should check out ARM microcontrollers. (those are the ones used in several different android smartphones)

Anyway, using the avr-stil, i made a nice system for my RFID locks. It stores up to 10 RFID tags in EEPROM, and you can erase/add new cards with a master key. It doesn't sound like much but the code is actually pretty intense, and it only uses 10834 bytes of the program flash (33%), and 407 bytes of memory (19.9%). So I either did an awesome job at reserving memory, or 32kb is plenty for arduino related projects.

EDIT:
You updated your post while i was typing this one, haha.
Next you want to buy an LCD screen and make a text based adventure with your buttons as the controller!
Last edited on
closed account (D80DSL3A)

Next you want to buy an LCD screen and make a text based adventure with your buttons as the controller!


I'm sure I would try to use the 2D analog joystick I just got for it (it's just 2 variable potentiometers). Just now playing with that for providing analog input.
It plugs right into a standard breadboard. Nice!

I got another idea for my button functionality, Another event type:
case 4:// time for 2nd click has just elapsed.
This way the user of this button can know to respond to that last click - it can no longer turn into a double click (no event=3 will be coming).

I'm on it!

EDIT: Thanks for all the great tips re. language features and a better compiler. The arduino IDE is pretty clunky.

I've also noticed that the 32Kb of memory seems to stretch pretty good. I have yet to write a program which exceeds 4Kb compiled.
Last edited on
The arduino is a house I'm not ready to live in yet.
@fun2code
Got some great ideas man. Looks like you're heading down the right path. There are literally infinite things you could do with that.
Btw, have you looked into software debouncing? In a perfect world, the moment a button is hit it pulls the line to HIGH, but in reality it can bounce from high to low several times in like, a 5ms period, depending on how the buttons manufactured. That could arise problems for you down the road.

@L B
Why's that?
Pages: 12