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
‘#45’ Articles at TC101 Fall 2015, Page 2
Introduction to Programming Python and C++

Tag Archives: #45

#Mastery12 – Creating C++ functions

Hello! This is about creating functions on c++. Actually, creating a function is pretty simple and easy to learn. First, let´s start defining a function. A function, is basically a group of commands arranged inside by a phrase or word that you choose. There are different kinds of functions. C++ has a list of different functions already made and available to use but you can always create your own too.

 

How to create a function? Very easy!

The structure of a function consists in…

 

A type  name ( conditions) { and coding that you want the function to proceed with

 

       A type would be for example: long, double, or integer.

       The name can be almost anything you want, except for the ones already used by c++ to perform another task.

       The values are the things you are declaring.

       and then in between {} you have to type whatever you want the function to do.

 

Here is an example of a function:

 

A function is usually written before and outside the main( ).  Functions are used to isolate different processes in a program. Here´s an example of a simple program; one that works with a function and one that doesn’t and they both do the same.

 

There are different types of functions, for example void doesn’t return any value. For functions that do return values there are different types like double, char, bool, string… When using functions that return values, make sure you make the compiler know to what value return like return a; or return x;

 

To call the function into the main() you can use a cout and type your function.

 

Here´s an example of a non-void function.

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

                     

  TIPS:

– Remeber to maintain the same type in the same variables on your function.

– Be careful with the braces and were to put them. Always close the function before typing the main( ).

– Be careful with what values you want your function to return… Example: return a; or return 0;

– Be aware that the function name you create can be used on c++ for another thing like main ( ).

– Remeber that if the program compiles, it does not mean it works so make sure you test your program in the compiler.

WATCH MY VIDEO https://youtu.be/NOLXBXg-yik

#Mastery19 – Use of loops with “while”

Hello! This is about using loops with while, as we saw on the past mastery about using loops with for, Loops are used to repeat a group code as many times as wanted. They finish in small and simple parts a complex process by repeating itself

 

How do you type a loop using while?

 

A basic while structure using a loop is…

 

while (condition){

code to do if the condition is true}

 

While has many conditions which can be used but compared to the “for loop”, while has to have a condition.

 

Do while- these are useful for things that want to loop at least once. The structure is very simple.

#Mastery20 – Use of loops with “for”

Hey! Here is my on how to use loops with for. Loops are used to repeat a group code as many times as wanted. This is one of the basic and most useful tasks in c++. A loop permits you to do a very small and simple task and summing up it gets into up to a big and complex task.

 

How to write a for loop?

 

The structure of a for loop is the following:

for (variable; condition; variable update) {

Things to do when the condition is true

}

 

Notice that in the true part (in between parenthesis) the second section, tells the program that while the conditional expression is true the loop should continue to repeat itself. It is very important for the conditions to be separated in parenthesis as we see en the example before.

 

For example, lets do a program in which we make use of this loop.

 Hey! check out this page I found about usual problems programmers usually have when coding.

http://www.cprogramming.com/beginner_programming_mistakes.html

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

 WATCH MY VIDEO 

#Mastery11 – Calling C++ functions

Hello, this is which shows how to call functions in c++. Using many functions in a program, lets you divide the work on the code in parts this has a pro because if you mess up during the coding of the function, the error would come up easier.

 

It is possible to call one function form another function (result). For example, if you are calling a function named time () inside of main ()

 

Int main ()

{time (); // This is calling the function time inside of main.

return 0;

}

 

Its is also possible to declare a function before calling it. For example:

 

Void time ()

 

Int main () {

 

            Void ();

}

     Return 0;

}

 

Remember to be careful with the order in coding, because every command has its specific place to be working. Sometimes, the compiler can do its work and display no errors, but don´t be completely sure, because sometimes the compiler may not display any message, but the error may me in the order of the commands.

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

WATCH MY VIDEO  https://youtu.be/9UuwAnWXiig

#Mastery09 – Basic types and their use in C++

Hello there! This is that will be talking about basic types and their use in C++. Let’s get started!

 

C++ is able to do many kinds of stuff depending on what you code, it is not all about the Hello World activity. C++ can handle many kinds of stuff and for that we need to learn how to make use of the types.

 

The programming code is not aware of where is all our data going to but one thing he needs to be sure of is to know what type of information it´s being handled.

 

Types can be classified in to:

 

               Character types: this collection can represent just one character. The most common and used one is char which stores in one byte.

               Numerical integer types: These range can store any kind of whole numbers, like 1 or 500 the thing here is that fractional numbers are not accepted.

               Floating-point types: These can let you represent values with decimal point just as 34.89, and let’s you interact with them.

               Boolean types: This type bool, can be only represented in two circumstances, TRUE or FALSE.

 

Here`s a table of types with its description:

 

Type

Description

bool

true or false.

char

single octet, one byte. Integer

int

integer

float

A single-precision floating point .

double

A double-precision floating point.

void

absence of type.

wchar_t

wide character

 

 

 

 

 

 

 

 

 

 

 

 

 

Every type differs from its size; they can take different amounts of memory.

 

In floating point types, size affects the precision of the calculations.

 

All of the types listed before are known as arithmetic types.

 

C++ does accept a big range of types based on the fundamental ones, the other ones are known as compound and is one of the most important skills in c++ language.

WATCH MY VIDEO https://youtu.be/vCDCJ9CrCl4

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

 

#Mastery09 – Basic types and their use in C++

Hello there! This is that will be talking about basic types and their use in C++. Let’s get started!

 

C++ is able to do many kinds of stuff depending on what you code, it is not all about the Hello World activity. C++ can handle many kinds of stuff and for that we need to learn how to make use of the types.

 

The programming code is not aware of where is all our data going to but one thing he needs to be sure of is to know what type of information it´s being handled.

 

Types can be classified in to:

 

               Character types: this collection can represent just one character. The most common and used one is char which stores in one byte.

               Numerical integer types: These range can store any kind of whole numbers, like 1 or 500 the thing here is that fractional numbers are not accepted.

               Floating-point types: These can let you represent values with decimal point just as 34.89, and let’s you interact with them.

               Boolean types: This type bool, can be only represented in two circumstances, TRUE or FALSE.

 

Here`s a table of types with its description:

 

Type

Description

bool

true or false.

char

single octet, one byte. Integer

int

integer

float

A single-precision floating point .

double

A double-precision floating point.

void

absence of type.

wchar_t

wide character

 

 

 

 

 

 

 

 

 

 

 

 

 

Every type differs from its size; they can take different amounts of memory.

 

In floating point types, size affects the precision of the calculations.

 

All of the types listed before are known as arithmetic types.

 

C++ does accept a big range of types based on the fundamental ones, the other ones are known as compound and is one of the most important skills in c++ language.

WATCH MY VIDEO https://youtu.be/vCDCJ9CrCl4

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

 

#Mastery10 – Basic output (printing) and input (text based) in C++

Hey there this is which is about output (printing) and input (text based) in C++. So let´s get started!

 

First what you want to know is that there are a few ways in which you can print something in your programs.

 

For outputting there is:

 

cout

std output stream

cerr

Std error (output) stream

clog

std logging (output) stream

 

This basically work the same all of them they just differ on their purpose. Cerr and clog are already predetermined to work as as error or logging strings or values.

 

The following actions would…

 (Not using the greater than symbols because the blog erases the content)

Cout xendl; – Print the value of x.

 

Cout 20 endl; – Print the number 20.

 

Cout “Hello” endl; – Print the string Hello.

 

The (less than symbol) operator inserts the data that follows it into the stream

 

 

cin

standard input stream

 

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

Cin, Lets the users to input some text (string) or actual value into the program. Is the way to introduce information to the coding and let it interact.

 

WATCH MY VIDEO https://youtu.be/Dhtw_9QTV3U

#Mastery04 – Submit work via Blog RSS and GitHub

Hey this is about RSS and Github

What is a RSS?

The RSS is a system that is kind of a bookmark where you can get subscribed to pages and get a feed of it in certain periods of time, this is actually really efficient because, you don´t need to be entering the page multiple times, you just need to subscribe and RSS will do all the rest.

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

This is a technology used by many people to follow their favorite webpages. Its is not a book mark. Bookmarks, when installed in your browser stay the same as they ore from the beginning. Rss lets you keep track of what is happening around and keeps your Bookmarks on date.

It´s really simple to get to use the “Really Simple Syndication” what you want to do is to hook yourself up with an RSS reader, there are many available online.

What is Gitbuh?

 

Github is a social programming platform where you can publish all of your coding works and share them to people. Publish them if you need any help or want to help others too. This site is kind of a facebook for programmmers. The libraries are called repositories in which you can save your programming works.

WATCH MY VIDEO https://youtu.be/l4iIsBH6r4M

#Mastery16 – Use of “else” with a conditional

Hello! Here is my that is about using else in conditionals. An else statement is used on conditional to set the false part. If a value that is introduced does not fulfill the true condition, there is when the else takes part in the process. This is used to have a response to a false condition.

 

For example:

 

If you want to create a simple program for grading, that describes when a student is approved or has failed the semester, this program would have to make the sum of the three partials and calculate the average. Let´s say the approbatory grade is 70. To start, you can begin it in many ways. I would choose to do it with an if condition.

 

The goal here is for the program to print the phrase approved or failed depending on the sum of the partial grades. This program, of course, to proof the use of the else statement.

 

To begin, we would have to type what we regularly do in all of the coding processes.

 

using namespace std;

 

Then, we would have to begin with the input of each one of the partials. For the program to get the average of the three and then with an if condition, tell if the student is approved or has failed.

 

The code would be:

 

Remember that to use an else statement you have to make use of the conditional with the true condition. Al else has to follow a conditional to work. When you write an else, the response has to be following the else in between braces, this helps the condition to realize what to execute when the false condition is applied. For example:

 

If(average>=7){

cout

}

else {

cout

}

 

Remember to always make use of the correct punctuation, spaces and symbols for the code. The semicolon is very important to be included at the end of each line (That is my most common mistake).

 

 

 

Here is the running program. As you can see, I used the else statement to print the string when the student failed.

Tip: if your program does not work when you are trying to compile do not freak out, the compiler will try to tell you what he doesn’t understand. Here is an example of an error, the numbers show the line and the number of character in which the error is placed.

 

 

The compiler says there is a semicolon missing in line 5 space 31…

 

 

 

 

Remember to check to learn how to use if conditionals.

 

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

WATCH MY VIDEO https://youtu.be/951plPJV2VE

#Mastery15 – Use of the conditional “if”

Hey! This is about using the conditional “if”. First things first we need to know what is it for. The conditional If is used when you want to give the program command a condition. This means that when you enter some kind of information to the program, it gives back a response depending on it´s condition.

 

Conditionals have their own symbology, here are the basics you need to know in order to begin with conditional coding.

 

> Greater than

>= Bigger than or equal to

! = Unequal to

== Equals to

 

What is the structure of an If statement?

 

To program something using the conditional “If” you have to begin with…

if (true statement) execute the next.

The true statement refers to a condition you choose to be done if what is introduced fulfills the condition. The true statement has to be always in between parenthesis. If what is introduced is true, the program proceeds to execute what is given to the statement. For example:

x = 1

If(x>o) {

cout

 

If you ran the program with this conditional, the resulting action would be displaying the string given, because 1 fulfills the condition 1>0.

 

If the condition is not true, then we would prefer to use the else option. What does else do? Else does the action of the false response. If what is introduced to the program doesn’t fulfill the true condition, then the else would be executed. For example:

x = -1

If(x>o) {

cout

 

else {

cout

 

If you ran this program with this conditional, the resulting action would be displaying the string given in the else command. This because -1 does not fulfill the true condition so the else command is executed.

 

For example, imagine you are doing a program for an ice-cream store. This store has two ranges of flavor which differ in price. If you are getting a flavor from group number one, the price of each cone is $20.00, but if you are getting a cone with flavor from group number two, the price of each cone is $30.0.

 

You would, first, need an action for the cashier to input in which group of  flavor the ice cream is, and then use a conditional to display which type of price is it depending on the type of ice-cream. Here is the example code:

 

 

WATCH MY VIDEO https://youtu.be/Q6ysIRGGoaQ

96

Normal
0

21

false
false
false

ES-TRAD
X-NONE
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Tabla normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Calibri;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-fareast-language:EN-US;}

 

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).