Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#c’ Articles at TC101 Fall 2015, Page 4
Introduction to Programming Python and C++

Tag Archives: #c

Quiz 7I got confused about the mathematic function of how…

Quiz 7I got confused about the mathematic function of how Fibonacci works, so that was my biggest problem. Palindrome was easier.Here are my codes:FibonacciPalindrome

NEIN, NEIN, NE… YES!I wasn’t even sure what factorials…

NEIN, NEIN, NE… YES!

I wasn’t even sure what factorials were before doing this WSQ. So, I’m really happy that I could complete it. I had an error with my loops, but I figured out that I had string(ed?) the same thing twice. That was my error, I got ride of it, and now my programm works like a charm.

You can check out my code here:

https://github.com/opezaimd/TC101/blob/master/WSQ09

Quiz 6I think I get it now:superpower.cppstar.cpp 

Quiz 6

I think I get it now:

superpower.cpp
star.cpp 

QUIZ 06

(The credit of the  image goes to https://flic.kr/p/4C37pr) Welcome to this special post. As you can see, it is a quiz. Here are my codes: https://github.com/anagloriaac/QUIZ06/blob/master/q1.cpp https://github.com/anagloriaac/QUIZ06/blob/master/q2.cpp

QUIZ 06

(The credit of the  image goes to https://flic.kr/p/4C37pr) Welcome to this special post. As you can see, it is a quiz. Here are my codes: https://github.com/anagloriaac/QUIZ06/blob/master/q1.cpp https://github.com/anagloriaac/QUIZ06/blob/master/q2.cpp

8 PinochoWSQ08 wasn’t really that hard. I used the book for the…

8 Pinocho

WSQ08 wasn’t really that hard. I used the book for the understanding of functions and to see some examples and understand more visually,  I used this webpage:

http://www.cplusplus.com/doc/tutorial/functions/

You can check my code here if you want:

https://github.com/opezaimd/TC101/blob/master/WSQ08

Masteries 15 & 16

On these masteries I’m going to show you what are IF and ELSE statements in C++ and how to use them. 

If and else are used in C++ when you want something to happen inside your code ONLY when a condition is given. 

On a flow chart, IF and ELSE look like this:

Source and more information

For example, in real life, your mom may tell you: “You are ONLY going to the party IF you score more or equal than 85 on your TC1017 exam. Else, you are not going to the party.”

For the purpose of this mastery, let’s creat that exact program. We will need an IF and ELSE statement, and some cin and cout commands we learned on mastery 10.

Let’s go ahead and create our “basic program” again.

Now, let’s grab our real life example. Let’s give the program the same condition your mom gave to you. Do as follows:

  1. Create two variables that will work as your score and the permition.
  2. Write the code were the program asks the user for the score (cin)
  3. Write the condition. 
    1. IF: the input (your score) is greater or equal than 85, the program will print a message where it says that you are going to the party.
    2. ELSE,

      the program will print a message where it says that

      you are not going to the party.

Now let’s test our program. Remeber to change directory, compile and then run.

I tested every possible condition the user could input. Remember that if your program stopped, you can simply run (./a.exe) again and the program will work. You don’t need to close the terminal and open it again. 

That’s the basic use of IF…ELSE and now you know how to use it, congrats! 😀

Mastery 10

Today, I’m going to show you some basic input and output in C++.

On masteries 1 & 7 we learned some basic output, which is used as “cout”. cout is used when the program prints information you gave it to it in the program. When you want to input information from the terminal, while the program is running, you need a variable and the “cin” command. 

In order to do this, we will create a program that asks the user for two integer numbers, and then the program will add those numbers and then print the result.

So, you will need our “basic code” that we learned on masteries 1 & 7:

image

Now that we have our basic code, we will write the program inside the braces. 

The first thing we need to do, is to establish the variables we are going to use. We need two variables for the numbers the user is going to input in the program and another variable that will work as the result. 
The variables need to be established inside the braces, and are written as:
int FIRSTVARIABLE, SECOND, THIRD;

image

Now that we have our variables, we can tell the program what it needs to do. For that, we will simply do as follows:

  1.  Print (cout) a question where the program asks the user for the variables (cin) 
  2. Write a math operation with the variables 
  3. Print the result:
image

And that’s it. You can use this principle to perform other math operations:

image

Now, run your program in the terminal. Remember to change the directory, compile your program and then run it:

Mastery 10

You now know how to do a basic program with inputs and outputs, congrats! 😀

MASTERY #19: Use of loops with “while”

So this is Mastery #20 and I’m going to tell you about the loop while. Let me tell you first that a loop is “is a way of repeating a statement a number of times until some way of ending the loop occurs”.  However, if you don’t tell your program when to stop, it will be […]

MASTERIES #19 & #20: Use of loops with “while” and “for”

  (The credit of the background images goes to https://flic.kr/p/dAus13 and https://flic.kr/p/hiFuew ) So this are Masteries #19 & #20 and I’m going to tell you about the loops while and for. Let me tell you first that a loop is “is a way of repeating a statement a number of times until some way of ending the […]

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).