iasteele

 

Areeb

Page history last edited by Areeb 2 yrs ago

What we learned in C++ Class

 

 

Day 1 

 

    Today we leanred the basics of C programming, while working on Microsoft Visual Studio .NET 2003. First, we started by making a new Win32 Console Project, after making windows open an empty project. The only thing we worked with today was the source file, were all the programming is done. Every project must have a main function, which is were the computer starts reading the program from. Then we learned how to display information on the screen:

 

printf("");

 

what to add  to let the project have outside information:

 

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

 

how to show a variable or a character:

 

%i, %c, etc

 

how to let the person input commands:

 

scanf("");

 

how to define variables:

 

int new_variable = x;

 

how to loop something, looping when a condition occurs:

 

while(1);

 

how to show a condition:

 

if(  )

        {      

        }

 

how to make a function:

 

void main()

 

and more things. Some important things are that you must have a starting and ending {} on functions and conditions. Also, the ";" needs to be used on all lines that only need to happen once. One = defines one variable to another, while == lets you use a condition, as with & and &&. Other conditions are <, > and !=.

 

We made a game in which you have to guess the number. At first, we made it so that we gave one set number, and they can input a number. Then we made it better, so you can input multiple numbers, and it would tell you if you got it correct. Then, we made the game so the number is random, and keeps the score of that round, the total score, and the par, and show them to the player so they can see how they are doing. Then, finally, we let the player choose the difficulty, set a par accordingly, and show reactions to show how well or bad they did.

 

Waiting for Class number 2 for more fun...

 

 

 

Day 2

 

    Today was our second day of C++ class. At first, we wrote a program in which we asked for a number, and then the computer counted up until the number given. At first I tried the brute force method, in which I wrote out all the possibilities, and what to type for them. Then we learned another way of doing it in which we can tell it to count up to the number automatically and it is more flexible. Then we created a calculator which could add, subtract, divide, or multiply numbers, even with decimals. And then after that, we made a program which could take strings of information, and write what is given in different orders. And finally, we started on a blackjack game. So far, all we did was make the deck, and make sure there was only one of each card, with their own number and suit.

 

 

Some things we learned today were:

 

if()

else if()

else()

 

which allows us to have many conditions for an event to happen.

 

for(set a variable to something; condition ; event2)

       {

             event1

 

        }

 

which lets us combine many functions into one.

 

char word[#]

 

which lets us have a string of characters instead of just 1 charcter variables.

 

Or even more sets of that group, such as

 

hand[2][11]

which means 2 hands with 11 cards each

 

word[0]

 

that lets us show the first letter of the word.

 

|| = or

 

 

gets()

 

that means get string

 

using float instead of int lets us get decimals

 

strlen(name)

 

That is a numerical value of the # of letters in the string

 

 We also learned how to use the debugging tool also in class. I have been told it is very useful, but I haven't found it useful enough now, so I'll stick with the old-fashioned way. You press the green arrow at the top to start the mode. F9 makes a red dot appear which is supposed to run the script one line at a time to find errors.

 

Next class we are gonna try to finish the Blackjack game.

Bye

 

 

 

 Day 3

 

Last class, we worked a lot on the Blackjack game, and we finished a first version of the game. We made many functions in the one main source file. The functions are called in order, and so if you want to call a function in the main function, or any other one, the one you called must be higher on the page. But mostly, on this day, we took everything we learned and put it on this program.

 

You can include

 

#include <time.h>

 

srand ((unsigned int) time(0));

 

int random(int min, int max)

{

    int range;

    int rval;

    range = max - min +1;

    rval = rand() % range;

    rval = rval + min;

    return rval;

}

 

 to make the numbers seem truly random.

 

Next class, we will improve the Blackjack problem.

 

Day 4

 

This is our last class of C++. First, we fixed up some problems of our BlackJack program, such as hiding the dealers hand, and making the ace switch between 1 and 11 when needed.

 

One of the last things we learned in this class was the

break();

command, which lets you escape a loop.

 

ALso, something I forgot to mention before was adding the

#include <string.h>

at the top, which lets you use strings.

 

you must use

variable = atoi(string);

to make a string into an integer.

 

I had a great time in C++.

 

 

Comments (0)

You don't have permission to comment on this page.