Tuesday, June 30, 2009

Beginning Sudoku Cheater Software

I'm planning on making a sudoku cheater program. Before I begin, I should study Sudoku. Sudoku is a board of 81 squares organized in 9 rows of 9 squares each. The typical sudoku board has just enough numbers on it for the player to guess the other numbers on the board. I guess I'm skipping a lot of necessary details. Each row must include numbers 1 through 9 and the same within each column. I play Sudoku sometimes ergo I'm aware of some of the techniques that are used to quickly find missing numbers and I think I may implement these techniques into the code but I've noticed that on the more difficult sudoku games where not many numbers are given or the numbers that are given strategically don't give you any hints as to what the other spaces could be, the trial and error method is required. The program could be entirely based on the trial and error method or I can have a couple functions that go through the most common techniques and then finally a function that looks for the rest of the numbers through trial and error.

Saturday, May 30, 2009

how many clicks?

blogspot:
to blog a new post on blogspot is 3 clicks (if i'm logged in)
1. clicking www.blogspot.com
2. clicking "new post"
3. clicking "publish post"

facebook:
depends on what you do there but that takes about 5 clicks as well

gmail
takes about 5 clicks to open chats with some friends and check some mails

google reader
takes about 5 clicks too... i wish google reader and google talk would come together so I didn't ahve to be on gmail for google talk and google reader at the same time. i'm not sure how much memory and bandwidth that takes up.

bottom line is that I can't wait for google wave. where else is that awesome spell checker being implemented?

Tuesday, April 28, 2009

Memorizing SDL

I read an article about the best study method. I want to learn how to use SDL, so I'm going to apply this method now. I'm going to try to recall whatever code I can from lesson 4 and type it here.

#include "SDL/SDL.h" // always need when SDL program
#include "SDL/SDL_Img.h" // need for .png files to display
#include <strings>

//screen attributes

const int scn_h = 640; //screen height
const int scn_w = 480; //screen width
const int scn_bpp = 32; // screen bits per pixel

/* darn, I'm not sure width was 480 (I'll check when I'm completely lost.) */

SDL_Event event; //structure to hold events for us to handle

// function prototypes

SDL_Surface * load_image (std::string); // returns pointer to SDL Surface with a parameter to a string

/*OK. I'm lost. Lazy Foo, defines several other functions before he gets into the main, but I barely remember I'm going to have to re read the whole section. Yes, I know that I said SDL was easy to understand since I pretty much know the C++ invovled but I don't want to be tutorial dependent for every function. I want to know the SDL library so I can do things off the top of my head with it.*/

In our experiments, when students repeatedly read something, it falsely inflates their sense of their own learning."

Saturday, April 18, 2009

C PLUS PLUS NEWB

I wanted to change my blog URL to www.cplusplusnewb.blogspot.com to avoid the negative connotations of the word "noob", but somebody already took that URL. I went to check out what cplusplusnewb is all about; turns out that cplusplusnewb is a very neat blog. I love the way this programmer organized the blog where you can see pictures of the the program in action, download the program, and download the source. The blog style is very clean, simple, and easy to learn from.

The Meaning of Noob

I just discovered that the word "noob" has very negative connotations.

"Contrary to the belief of many, a noob/n00b and a newbie/newb are not the same thing. Newbs are those who are new to some task* and are very beginner at it, possibly a little overconfident about it, but they are willing to learn and fix their errors to move out of that stage. n00bs, on the other hand, know little and have no will to learn any more. They expect people to do the work for them and then expect to get praised about it, and make up a unique species of their own. It is the latter we will study in this guide so that the reader is prepared to encounter them in the wild if needed." -urban dictionary on the definition of noob

I'm not a noob if that's what a noob is. I don't wish to be praised by others' works. I hope to become a great programmer, but I know now that I'm far from being one. I'm still a newbie learning from my programming errors and learning from programmers that I'm a mere fraction of. I think this blog's URL is cplusplusnoob.blogspot.com and I'm not sure there is anything I can do to change this. :(

edit: I managed to change the site name to www.cppnewb.blogspot.com

I wish I could have changed the site name to cplusplusnewb, but that was taken by somebody.

Changed Colors on the C++ Blog

I changed some colors. I'm bored of the white text over a black background I had before.

Friday, April 17, 2009

Pointer to Functions

I've seen pointers point to all the fundamental types and I've seen pointers point to the compound type known as array but I recently learned that pointers can also point to functions. To declare a pointer to a function that returns an integer and has an integer as its parameter you write

(int)(*pt)(int);

Say you have a function called square. The square function returns an integer and has an integer as its parameter.

int square(int x) { return x * x ; }

Now you want to assign the pointer to the function. Note: The address of a function is in the function name, therefore

pt = square; // is valid.

now if you want to call the function through the pointer, all you have to do is

(*pt)(2); // is 4

or simply

pt(2); // is 4 too

The pointer's ability to point to a function is useful when one wants to create a function that has other functions as its parameters. You would not want to create entire copies of the function, rather you'd want to refer to the function, therefore saving space and time.

Monday, April 13, 2009

Learning the Simple DirectMedia Layer (SDL)


I just discovered SDL and some great tutorials at http://lazyfoo.net. I'm on lesson 5 now, but moving quickly through them since I understand most of the C++. Before, I would look at all code referencing functions in a library and have no idea what I was looking at, but now after about a year of studying C++ everything makes sense. I'm already getting a feel of what event driven programming is and how it's implemented by reading through lazy foo's tutorial. I'm somewhat sidetracking at the moment from my goal -- inspired by John Carmack -- to program for my Nokia cell phone. I guess as long as I'm focused on programming, I'm being productive.

Friday, April 3, 2009

Amazing Array Discovery for Scrabble Cheater

Scrabble Cheater Intro.
I don't know if I've mentioned this here before, but I've been working on a scrabble cheater. I know you're probably thinking "aren't there scrabble cheaters on the internet for free?" I've seen some of them myself and they're mediocre. I hope to make one that's fast an organized. I want the user to just be able to enter the characters available and for the program to output all possible words that can be made from in those letters in order of least to greatest word size.
The ArrayAlign Center
Well, I just disocovered a very important aspect of c++. I didn't know this before but you can actually access a string in an array and access a specific character in that string with a 2-dimensional array. Here's some source code to illustrate:
include string
string Array[4] = {"dog", "cat", "house", "iguana"};
cout Array[0][0];

The code above would output the first character in first element in the array of strings (e.i. 'd')

cout Array[1][0];

The code above would output the first character in the second element in the array of strings (e.i. 'c')

Thursday, March 19, 2009

Blabbling about Pointers

I didn't know what the point of pointers was until yesterday upon reading Prata. I learned that you use pointers to allocate memory with the new operator. I guess there is no other way. Before I found about runtime decisions vs. compile time decisions I thought that there was no point to pointers and you could always just pass by reference. What about runtime decisions vs compile time decisions? well, a runtime decision is a decision that is made while the program is running and a compile time decision is a decision made while the program is being compiled. When you're making a very large program you want to manage memory so that variables or arrays aren't all loaded into memory if they don't need to be loaded into memory. There's a lot of talk about heap or stack. I can't remember where memory allocated by new goes. Any who, maybe you don't want memory space to be allocated until certain conditions are met.

if (GetAnswer() == true;)
{
int * p_number = new int; // allocated memory with new
cout << "You get " << *p_number << " points!"; //dereferencing the pointer to display value and not address } However, you usually don't want to use pointers for programs with just a few variables. Another cool thing about pointers and allocating with the new is dynamic binding. Static binding is when you create an array with a fixed amount of elements, but when you dynamically bind you allocate an array and you make the size of the array a variable. e.g.
Code:

#include <iostream>
using namespace std;

int main()
{
int ArraySize;
cin>> ArraySize;
int * p_numbers = new int [ArraySize];

for (int x = 0; x <= ArraySize; x++){ p_numbers[x] = x; cout<<<>>f;
return 0;
}

You wouldn't be able to complete the same task with normal arrays.



Wednesday, March 18, 2009

CPlusPlus quiz


I was just doing http://www.mycppquiz.com until I realized that I not ready. I must finished Prata's C Primer Plus 5th edition before I try doing that test again.

Monday, March 16, 2009

What's your Fractional Age?


I'm making a relatively [on the relativity of "light coding"] simple program that calculates a persons age with its fractional part (COPY PASTED from coderrach's Blog. [the text before this parenthetical]). I made this program to remind me how much time I have until I'm a year older to remind me that I shouldn't waste time on video games and other things that aren. I just finished! Holy cow, that took a while. I've been working on it for at least 4 hours, thinking of how to solve all the problems.

list of some problems I encountered [don't laugh]
  • Days left until your birthday devided by 365 is not the fractional part of your age; however it is the fraction of a year until your birthday.
  • Amount of days in each month is not 30 [I did not try to code for each month. I used 30.5 (close enough) Though, if you're curious, the average of days in a month out of all the months is 30.42 (rounded)]
  • When birth month was greater than current month, user was a year older.
  • When birth month was less than current month, months left until birthday was not birth month - current
  • "1 exit status. Permission Denied." Dev-C++ failed to let me know that my program was running therefore I was enable to compile. For 10 minutes, I wasted time changing my soure code thinking my code was bad. Arggg!
Here's the code for the program.

Code:

//caclulate your age in years plus its fractional part

#include <iostream>
using namespace std;

float DaysOfYearLeft (int, int, int, int);
int GetYears (int, int, int, int);


int main()
{
float age;
int bday; // birthday
int bmonth;
int byear;
int cday; // current day
int cmonth; // current month
int cyear; // current year
float fyear; // fractional year
float fday; // fractional day
float fage; // fractional age is the sum of fyear and fday


cout<<"This program calculutes your age plus the fractional part of your age.";
cout<<"\n\n Enter your numerical birth day, month, and complete year in that order each\n value seperated by a single space.\n";
cin>>bday; cin>>bmonth; cin>>byear;
cout<<"\n\n Enter the current numerical date day, month, and complete year in that order \neach value seperated by a single space.\n";
cin>>cday; cin>>cmonth; cin>>cyear;

fyear = GetYears (byear, cyear, bmonth, cmonth);
fday = 1 -(DaysOfYearLeft (bday, bmonth, cday, cmonth)/365) ;
fage = fyear + fday;

cout<< "\n\nYour age with its fractional part is "<< fage;
cout<< "\n That is " << GetYears(byear, cyear, bmonth, cmonth) << " years and "<< 365 - DaysOfYearLeft (bday, bmonth, cday, cmonth)<<" days.";
cout<< "\n" << DaysOfYearLeft (bday, bmonth, cday, cmonth) <<" days until your birthday!";


char f;
cin>>f;
return 0;
}

float DaysOfYearLeft (int bday, int bmonth, int cday, int cmonth){

float monthsleft;

if (bmonth > cmonth){
monthsleft = bmonth - cmonth; //months left until next ageplus1
}
else
if (bmonth < cmonth){
monthsleft = 12 - (cmonth - bmonth);
}
// function does not yet account for current month equal to birth month

float daysleft = (monthsleft * 30.5 + bday) - cday;

return daysleft;
}

int GetYears (int byear, int cyear, int bmonth, int cmonth){

int age;


if (bmonth > cmonth){
age= (cyear - byear) - 1;
}
else
if (bmonth < cmonth){
age = cyear - byear;
}

return age;
}
list of problems trying to get the HTML right on this post:

Friday, March 13, 2009

Structures

I just learned about structures yesterday. I'm going to write up what I learned to reinforce some knowledge.

struct Person {char Name[20]; int Age; float Height;};

That's how you declare a structure. According to Prata, you want to externally declare structures so all functions can make use of them. Yes, programmers discourage declaring global variables or externally declaring variables, but recommend the external declaration of structures. This is how you use structures in the main function after having defined the structure before the main:

Person you = {
"CppNoob",
20,
172.0
};

or Person you = {"CppNoob", 20, 172.0}; // all the same

Now you can print you's values

cout<<"Name: " << you.name << " Age: " << you.Age << " Height:" << you.Height;

Saturday, March 7, 2009

Programmers on Blogger Suggestion

There are 61,300 blogger users that are interested in programming. I think Google Blogger should take this fact into consideration and create a source code feature. I find posting my source code somewhat difficult here.

Perhaps Blogger's programming team can get ideas from http://pastebin.com/ or http://www.cplusplus.com/forum I particularly like CPLUSPLUS.com forum's feature. You just put your code between [code][/code] Let me show you.

input:



output (different input but I just wanted to give blogger team and idea of what I want):

Comparing Strings in C++

#include
int compare( const string& str );
int compare( const char* str );
int compare( size_type index, size_type length, const string& str );
int compare( size_type index, size_type length, const string& str, size_type index2, size_type length2 );
int compare( size_type index, size_type length, const char* str, size_type length2 );

Sometimes, you want to compare two different strings for some reason. How do you compare strings in C++?

Easy, use the compare function defined in the string library. Look at all those function prototypes with the same header. I'm pretty sure this is called function overriding or overloading, when the same function name can have different parameters and handle these parameters differently. In this case we have variety of different functions with the same name, different parameters, but they all do the same thing in the end which is compare strings.

int compare( const string& str );

I have no idea what the parameters in the function above mean. Looks like this function has a single parameter: a constant string? I don't know what the ampersand is supposed to tell me! I just realized that I need to be more aware than I am about compare being a member function of the string type(class), therefore in order to use compare you have to create a string object and use a membership operator (e.i. a dot) between the object and the member function.

EXAMPLE SOURCECODE ON USING COMPARE WITH TWO STRINGS OH YAY:

string x = "blah";

string y = "nope";

int t;

t = x.compare(y);

cout<<
see x.compare(y)

Darn. I finally understand. I just didn't think you had to declare what type of information was in the address. Now int compare( const string& str ); makes complete sense. This function accepts a constant string, but

instead of taking in a copy of the string, it takes the address of the string to compare the actual string and not a copy of the string. Fascinating!

if i were to create a function

int funct (int &y){

y = 10;
}

int main () {

int y = 5;

funct(y);

cout y; // psuedo code. add insertion operator.

the y variable would be changed and print 10 instead of 5. if i wouldn't have made the function accept the address of a the variable i'm passing to it then it would just create a copy of the variable, a local variable. try stuff out.
see http://www.cppreference.com/wiki/string/compare
i'm tired.

Friday, March 6, 2009

C Plus Plus Terminology

(order of what first comes to mind)
integers, floating points, boolean, array, classes, objects, instances, polymorphism, virtual functions, compound types, types, operator, member functions, member variables, streams, escape characters, ASCII, loops, token, delimiter, header, constructor, destructor... Check out the cpp's creator's glossary of terms.

Wednesday, March 4, 2009

Wii Internet Capabilities

My cousin has been testing out Wii Internet ever since I bought it for only 5$ dollars, and I was surprised by Wii Internet's capabilities:
(see How To Get Wii Internet if you don't have it)
  • you can go on facebook
  • you can email someone
  • you can chat using web messengers
  • you can watch YOUTUBE videos
I'm not sure if you can watch flash videos... to be continued...

How To Get Wii Internet

  • make sure your wii is connected to your WiFi connection
  • go to wii shops on the wii menu
  • go to start shopping
  • go to buy points
  • go to buy points with visa
  • input visa information to buy points
    • internet app only requires 500 points so buy the minimum 10$ for 1000 pts
  • go back to Start Shopping
  • go to Channels
  • buy internet Channel for 500 pts
  • wait for download to complete

    see Wii Internet Capabilities: what can you do with internet wii?

Monday, March 2, 2009

C Primer Plus (5th Edition) by Stephen Prata

I bought a book at Borders today: C Primer Plus (5th Edition) by Stephen Prata. I've been wanting this book for a long while, but there's a somewhat funny story behind it. Without knowing, I've been borrowing the third edition from the Orange County main library for several days now. As I was reading the third edition, I recognized that it had the same name as that blue C Primer Plus book I saw at the top of amazons best sellers in C++ months ago, but I didn't make the connection. When I looked up the book at Borders.com to see if it was in stock, I saw that they were authored by the same guy, Stephen Prata. "Stephen Prata is a professor of physics and astronomy at the College of Marin in Kentfield, California, where, in addition to astronomy and physics, he does computer science." says Google and the back of the book. My understanding of the language is advancing steadily. Yesterday, I finally learned (upon reading some of the third edition) that cout is an object of the class ostream in the iostream library. [see cplusplus.com on cout for further reference]

C Primer Plus is a mega plus over C++ For Dummies (7 in 1). C++ for Dummies by Jeff Cogswell has so much useless text. I'll try to get some examples when I get my hands on the book. For Dummies likes to get the reader interested, but I don't think that works out when the writer is a computer scientist. Jeff Cogswell's trying to keep my interest just annoyed me. In C Primer Plus, Stephen Prata wastes no text on useless. He surprised me from the very first chapters by already introducing the importance of classes and objects in programming. I have to admit, though, I would be somewhat lost if not for having read C++ For Dummies.

Saturday, February 28, 2009

Print Screen Project [PSP]

If there is something I do often, I use the print screen key. The process of getting an image using the print screen key takes way too much time. Think of all the steps involved:

1) press PrtSc
2) open Microsoft Paint
3) press Ctrl+V to paste the screen image

Wouldn't the whole world be a lot happier if we could just press a key and the screen image would automatically be saved in a JPEG file? I'm not the only one searching to tackle similar problems. I'm trying to find the function for PrintScreen on the net, and then I'll just use stream input and output to create a jpeg file containing the image somehow. I don't know how. To be continued...

Friday, February 27, 2009

How Long Did I Take to Learn C++?

I wrote my first post on this blog May 25, 2008, and today is Februrary 27, 2009. I've been learning C++ for about 9 months, but I've been learning about programming in general for a long while more. I started Java before I went into C++. I stopped learning Java for two reasons:

1) I couldn't find out how to make Java programs "executables". Not being able to send my friends my java programs didn't make java programming very rewarding. With a C++, I could compile my sourecode directly into an executable file I could send to friends.

2) I couldn't understand constructors. I couldn't understand constructors easily in C++ either, but after watching tutorials on youtube by antiRTFM, I was enlightened about constructors and desctructors and a lot of other things.

I feel like I really understand C++ and I could take on Java with ease if I wanted to. The only concept I'm still having trouble with is polymorphism in programming. Oh well, I'll figure it out.

Skype Auto Caller [with time delay]

I was experiencing some horrible internet connection last night while I was talking to my girlfriend on Skype. I was going offline about every half an hour or so, and I didn't want to have to use my mouse or keyboard to call my girlfriend back; I wanted there be a way for skype to just automatically call that specific friend every time the call turned off. I thought of different ways I could solve the problem. I was thinking that I could find functions for audio output and make a function to turn audio output into a boolean value that would be false when there was no output and true when there was. Before I went on, I decided to make sure someone hadn't already created a solution to my problem. I didn't find an auto caller, but I did find some useful information that would make things a lot simpler.





I was googling around and found out that you can create a short cut to call a specific skype user. All I needed now was to figure out how to get this short cut to open all on its own. I thought I could have an executable run that would open the file, and I remebered a line of code for opening files with C++ from a yahoo question. Now all I needed was to block the file opening line in a never ending loop. I did that but I knew that would create a program that opened the short cut continuously (which doesnt seem like such a bad idea now that I think of it). So, I went looking for the sourcode for a time delay that would cause the open file in to execute only after every certain amount of time. Finally, I ended up with this:

// include insertion symbols
#include stdio.h
#include stdlib.h
#include time.h

void sleep( clock_t wait );
int main( void )
{
long i = 6000000L;
clock_t start, finish;
double duration;

while (true)
{
// Delay for a specified time.
printf( "Delay for 2 minutes\n" );
sleep( (clock_t)120 * CLOCKS_PER_SEC );
printf( "Calling!\n" );
system("C:/calluser.url");

/*the line just above this comment opens the shortcut you have to make. Right click desktop, click new, click short cut, and type in

skype:username?chat

and then press OK or whatever. In the case of my sourcecode, the shortcut's name is calluser with the url extension, but you can name the shortcut whatever you want. My shortcut's location is C:/. Remember to replace "username" with a username on your skype contact list or a number.*/

}
system ("PAUSE"); // unncessary and not reccomended
}


// Pauses for a specified number of milliseconds.

void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while
( goal > clock() ) ;
}

/*********************************************************

There's potential for more features. I could change some literals into variables that can be changed by the user so I don't have to change the source code and compile every time I want to change the length of the delay. I could also just eliminate the time delay all together so it would execute continuously, but now that I think of this method again, I remember that you get an error message when you try to call someone when you're offline and if I had it do that I'd get a 1000 of those error messages every time I went offline with the auto caller program running, so that's no good. The delay stays! I could add some code that creates the url for you and asks you for the username or number using some stream methods.

**********************************************************/

Wednesday, February 25, 2009

I'm Flying On Python


I got a book on Python at the Orlando Orange County main library: "Learning Python" by Mark Lutz and David Ascber. I didn't know that Python was an interpreted language i.e. a language that is compiled into byte code to be converted to machine code only during every execution through Python's bytecode translator. I would like to learn how to program in CPP without an environment (IDE): just a plain text editor and a the compiler for me. The book says that about half a million to a million people are programming in Python. I wonder how many people program in C++. What are the odds?

Thursday, February 19, 2009

So Many Subscriptions

I'm subscribed too way too many e-mail providers, forums, and social networking sites.

Cplusplus
Gavedev
Allegro

Future of Hello Worlds

I think in a future post I'll compile the hello world source code in many different languages: C, C#, C++, Python...

I haven't been blogging here often. I'm still debating over whether to blog here or Xanga. I love Google products, but I'm a premium member of Xanga and I enjoy the benefits.

Wednesday, January 28, 2009

Get Decimal Value Of Any Character

// this program gives you the decimal value of any ansii character
// there's shorter way to make this program but I wanted to use functions

#include
#include
using namespace std;

char GetLetter(); // this is a function prototype
int GetNumberFromLetter(char letter); // this is another function prototype
void PrintNumber(int number);

int main() // the main function
{
cout<<"Enter a letter, press Enter, and get its designated number:"<
while (true) // the program never terminates itself.
{

PrintNumber(GetNumberFromLetter(GetLetter())); //this line calls 3 different functions
}

return 0;
}

char GetLetter(){ // function definition of the function prototype

char letter;
cin>> letter;
return letter;
}


int GetNumberFromLetter (char letter){

int number = 0;
number = letter;
return number;
}

void PrintNumber (int number){
cout<< number << endl;
}