Wednesday, February 20, 2008

[Blogs][Week]

Because of lack of time and lack of class, this blog will cover last Monday (the 11th) to today.
Monday:
Monday was not a very exciting double, considering all I was doing was trying to figure out what pointers did, how structures worked, and started working on arrays. I moved on from pointers unsuccessfully. I realize what they do, just not how they work. The tutorial was not very helpful, for it was more of a complicated example than an actual tutorial. So I moved on to structures, which made a bit more sense. Structures are used mostly for database programs, as it would seem.

int main()
{
database employee;

employee.age = 22;
employee.id_number = 543927;
employee.salary = 12000.21;


Structures and pointers are probably not going to play a big part in our project for now, unless someone flies out of the sky and explains it to me in layman terms.

With that, I moved on to arrays. An array is basically a matrix, but not quite. A more correct wording is that a matrix is an array. After writing out the tutorial and seeing that it worked, I decided to mess around with the numbers a bit. The double was over by now, and due to school holidays and snow days, I didn't have class until Friday, which was a short class.

Today
Today I messed around with the arrays some more. Essentially, I was just doing the same thing. Here is the code:

#include

using namespace std;

int main()
{
int x;
int y;
int array[50][50];


for ( x = 0; x < 50; x++ ) {
for ( y = 0; y < 50; y++ )
array[x][y] = x + y;
}
cout<<"Array Indices:\n";
for ( x = 0; x < 50; x++ ) {
for ( y = 0; y < 50; y++ )
cout<<" "<< array[x][y] <<" ";
cout<<"\n";
}
cin.get();
system("\n pause");
}



It makes a 50 x 50 array of x + y.
That's it for now.

Friday, February 8, 2008

*Blogpost

I started out the class period trying to fix my simple switch program. I was, for the most part, unsuccessful, though I did come up with a momentary explanation. The problem is that the message displayed doesn't appear on the screen after the case is activated, with the exception of a few times. What I think is going on is that the program has already registered the message from previous attempts so the time it takes to display and the time it takes to close the program is so small that the message doesn't appear. Whenever I change the code, the message comes up for a brief moment, then the program closes. That is the other problem, I can't seem to get the program to pause, but that's the least of my worries right now.
I moved on to pointers for the sake of keeping up with Max. Basically, I know what pointers are and how they work, but I don't know how to use them in an actual program. This seems to happen a lot. I understand what the code does, but I can't get it to function properly. I must say it is a pain.

Wednesday, February 6, 2008

Case 6: Blogging

Because I ran out of time to post a blog on Monday, and there was a snow day on Tuesday, and today was a school holiday, I will be posting today as if it were Monday.

I moved on to switch cases, and I found that they are easier than they sounded. For lack of a better example, they are like program menus. Here is a chunk of code:

switch ( input ) {
case 1:
cout<<"You chose 1.";
break;
case 2:
cout<<"You chose 2.";
break;
case 3:
cout<<"You chose 3.";
break;
case 4:
cout<<"You chose 4.";
break;
default:
cout<<"Why can't you follow directions?";
break;
}
What happens is you enter a number between 1-4 and whatever one you choose, it will run that case. If you pick something other than that, it will display a default message. Currently, I've gotten the cases to work, but the default doesn't work. Another problem is that the message (ie. You chose 4) doesn't stay. It quickly displays and then the window closes. That should be easily solved, but I didn't have time to solve it because...
The second half of the double period was a presentation of Zhanar's Sudoku Solver. We proved that, when solving a sudoku, I am smarter than a computer. That might be an incentive for her to make a logical Sudoku Solver, for the way that her current program works doesn't use logic. We went through the code and Zhanar explained what everything did. I didn't necessarily understand what all the code did, but I was able to understand the basic functions of each bit when explained. It was a good presentation.

Friday, February 1, 2008

Functions!!

These past two days I've been working with functions. Actually, I haven't done all that much. Yesterday (Thursday) was not a very productive day. The extent of my learning was reading about functions on the C++ Tutorial site. Due to many distractions, I never got to the coding part. Today, however, I did. It was as easy as I figured it to be. My only problems were human error (forgetting an int main() and a few ;'s. I actually solved a problem on my own, but it turned out to be my own fault again. I forgot to add cin.get(); at the end. Here is the code:


#include

using namespace std;

int mult ( int x, int y );
int main()
{
int x;
int y;

cout<<"Please input two numbers to be multiplied: ";
cin>> x >> y;
cin.ignore();
cout<<"The product of your two numbers is "<< mult ( x , y ) <<".\n";
cin.get();
}

int mult (int x, int y )
{
return ( x * y );
}

This program, which is an example from the tutorial, asks you for two numbers and multiplies them. A very basic example of functions.

I still have more to work on with the functions. The more advanced functions will be tougher and, judging by what's ahead of me in the tutorials, I might want to spend more time with the simpler things and make sure I have them down.