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

Tag Archives: #include

#WSQ08 On to functions.

 I´ve been studying functions for a little while, in this occasion I was able to rewrite the code from the wsq03 and improve certain parts of the code with functions.

Functions are an essential tool when we are writting code, because it makes our lifes easy, just think about writting the same formula over and over again in a programm…when all you have to do is to create a function and then called it as many times as you want. Programming ain´t easy, but it´s interesting how every technological device works with some kind of source code.

 

 Here´s my code.

 

#include <iostream>
#include <math.h>
using namespace std;

double addition  (double a, double b){ //addition is the name of the function
return a+b;
}

double sustraction (double a, double b){
return a-b;
}

double product (double a, double b){
return a*b;
}

double division (double a, double b){
return a/b;
}

int remainder (int a, int b){
return a%b;
}

void newline(){
  cout<<endl;
}

int main(){
double a;
double b;
cout<<"Hi, I´m a calculator of two numbers, I will make operations of addition, product"<<endl;
cout<<"sustraction, division and eventually calculate the remainder between the numbers you´ll give me"<<endl;
newline();
cout<<"Please, give me the first value "; cin>>a;
newline();
cout<<"Please, give me the second value "; cin>>b;
newline();
cout<<"The addition of the numbers equals to "<< addition(a,b)<<endl; //We are calling the function
cout<<"The sustraction of the numbers equals to "<< sustraction(a,b)<<endl;
cout<<"The product of the numbers equals to "<< product(a,b)<<endl;
cout<<"The division of the numbers equals to "<< division(a,b)<<endl;
cout<<"The remainder of the division equals to "<< remainder(a,b)<<endl;

return 0; //...So the programm wont return values.
}

WSQ06!!

Here is my code, you have to guess a number that is randomly selected by the program. I did it with no help (except for the time/rand thing).

Hope this helps you!

#WSQ06 #Tc1017

 

#include

#include

#include

using namespace std;

 

int main() {

  srand(time(0));           //time changes, the number changes

  int r=1+(rand() % 100);

  int x;

  int count = 0;

  cout

 

cout

cin >>x;

count = count+1;

 

while (x!=r){

  if(x

  cout

  cin >>x;

  count = count + 1;

} else {

  if (x>r){

      cout

      cin >>x;

      count = count + 1;

 }

  }

}

 

cout

  return 0;

 

}

#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

# WSQ03

In this wsq03 we have to make a code in which the user neeeds to enter tow numbers and the program has to make the addition, substracction, division, and reminder of the numbers the user enter.#include using namespace std;int main () {int x , …

#Mastery01 -Ability to create C++ file and run from command line

Hi today I´m doing that is about knowing how to create a c++ file and run it, and we are making the “How are you doing?” program that is actually pretty simple and easy to do.

First, you have to make sure you have a text editor. The best option is to have one specially made for programming because that way, when you are writing your code line, the editor marks each word depending on its function. This makes easier, for instance, to realize when you are coding wrong. For this, I use atom, and it is available for both operating systems.

Another thing you need to have is a compiler, if you use Mac, it is all ready installed and it´s called terminal. If you use Windows, you con download Cygwin. Make sure, when installing Cygwin, that you don´t download the whole package, just the stuff you need for the course (you can check out Ken´s video on how to download Cygwin for Windows on his channel.) Link: https://www.youtube.com/watch?v=i2h_976SpV0

So these are the steps you need to follow to program How are you doing? In c++: 

First you have to open up your text editor, and make sure you save it first (easier for me) with any name you want with ending in .cpp. Make sure you remember where you saved it because you are going to need the direction when compiling.

You need to start on first line writing

And second line using namespace std;

And finishing your code, you have to write retun 0; } (you can already write it down if you want to).

Remember to be careful with spaces and most important, don’t forget to put a “;” at the ending of each line. Don´t worry if you miss one, you the compiler will show up the error.

 

 

Then, after the first two lines, type int main() {cout . The cout command means that it is going to print anything that is following that. Typing words in between “” gives them a string value. The endl; means end line.

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;}

Finally, you have to open your compiler. First you need to change directory, for this, you have to type cd Documents/ (This obviously if you have the file saved on your documents.)

 

 

Then type ls (LS), which gives the list of documents saved on that direction. When you find your document (howareyoudoing.cpp), type g++ howareyoudoing.cpp, this transforms your code in to g++.

 

At last, you have to type to run it, ./a.out (if using Linux or Mac) or ./a.exe (when using Windows). And that´s it! You have finished your first program.

 

C++ Libraries #Mastery13

Libraries are important since they contain predetermined commands used to trigger several actions. For instance, we have the C++ libraries one of which is the iostream which includes commands as cout or cin (for output and input). In order to include a library in the code you must write as follows:

Nameofthelibrary 

The Nameofthelibrary depends on the type of commands or functions you’re looking for. For instance, if you want to do a logarithmic function you would probably like to search for a library related to math which in this case would be cmath . 

In this code, several C++ libraries were used to include commands and functions:

                   

 

Here are the several references for calling libraries: http://www.cplusplus.com/reference/

Thanks! 

#WSQ07-Sum of numbers

In this task I need to be able to make a program that can evaluate a range of numbers and make an operation (for example addition) so it will make a specific math equation like the following case:

if you give the programs the values of 1 and 10, it is going to interpret them like this: 1+2+3+4+5+6+7+8+9+10

At the begining and realizing what I was going to do I thought it was kind of difficult, but then Marco (a friend of mine) help me out with my code and the mistakes written inside the editor, until then I found a simpler way to make my program work.

Here are the results.

 <iostream>
 using namespace std;

 int main(){
  int sum=0;
  int x,y;

  int number=x;
  cout<<"This is a programm that can make the operation of addition in a range of values "<<endl;
  cout<<""<<endl;
  cout<<"Please give me the lower value ";
  cin>>x;

  cout<<"Please give me the upper value ";
  cin>>y;

  if (x>y){
  int temporal; //Store data, save data

  temporal=x;
  x=y;
  y=temporal;

  }

  for(int counter = x; counter <=y; counter++)

    sum += counter;

    cout<<"The result of the numbers from "<< x << " to "<<y<< " = "<< sum <<endl;

  return 0;


 }

Fun With Numbers!

Today I did a little program where you gave two numbers to it and yo got the sum, rest, product, division an remain.

It was easy once I understood the structure of it, getting help in https://github.com/MiguelAngelCardenas/WSQ03/blob/master/NUMBERS.cpp

Here is my code:

using namespace std;

 

int main() {

 

int num1, num2, sum, rest, prod, D, resid;

 

cout

cin >>num1;

cout

cin>> num2;

 

sum = num1 + num2;

cout

cout

 

rest = num1 – num2;

cout

cout

 

D = num1/num2;

cout

cout

 

resid = num1 % num2;

cout

cout

return 0;

 

}

#WSQ06

 <iostream>
<cstdlib>
<ctime>

using namespace std;

int main() {
  int y, intentos=0;
  srand((unsigned)time(0));
    int x = rand()%100+1;

  do {

      cout << "Guess my number between 1 to 100"<<endl;
      cin >> y;


      if (y>x){
          cout << "I´m sorry, " << y << "The number is too big" << endl;
      }
          else if (y<x){
              cout << "I´m sorry, " << y << " The number is too small." << endl;
          }
              else if (y=x){
                  cout << "Congrats, the correct answer was " << x << endl;
              }


  } while (y!=x);

  return 0;
}

#WSQ05-Temperature

I´m becoming more familiar with the commands of c++, right now i eventually make a programm that can convert from Fahrenheit to Celsius and vice versa.

It was kind of difficult at first, but once I saw a video about loops and if´s, well…it was all cleared out for me, now I can ressume my skills acquired in the homework in the following statements:

-You need to assign a value before the if´s

-You need to be careful with the “;”

-Dont give up!!!

here´s the video that help me improve my skills

https://www.youtube.com/watch?v=mSRs9WGrvqA

 

My code:

#include <iostream>
using namespace std;
int main(){
    int x;
    char c;



    cout<<"Choose a convertion"<<endl;
    cout<<""<<endl;
    cout<<"1. Celsius  to  Fahrenheit"<<endl;
    cout<<""<<endl;
    cout<<"2. Fahrenheit to Celsius"<<endl;
    cout<<""<<endl;
    cin>>x;
     if(x==1){
          float x;
          cout<<"Enter the temperature in Celsius degrees"<<endl;
          cout<<""<<endl;
          cin>>x;
          cout<<""<<endl;
          float y=(x*9/5)+(32);
          if (y<212){
  cout << "Water does not boil at this temperature (under typical conditions). "<<endl;
}

if (y>211)
{

  cout<< "Water does boil at this temperature (under typical conditions). "<<endl;

}
cout<< ""<<endl;
if (y<32){

  cout<< "The water is frozen"<< endl;

}
          cout<<x<<" Celsius degrees equals to "<<y<<" Fahrenheit";
      }else{
          float a;
          cout<<"Enter the temperature in fahrenheit degrees "<<endl;
          cout<<""<<endl;
          cin>>a;
          cout<<""<<endl;
          float b=(a-32)*5/9;
          if (b<212){
  cout << "Water does not boil at this temperature (under typical conditions). "<<endl;
}

if (b>211)
{

  cout<< "Water does boil at this temperature (under typical conditions). "<<endl;

}
cout<< ""<<endl;
if (b<33){

  cout<< "The water is frozen"<< endl;

}
          cout<<a<<" Fahrenheit degrees equals to "<<b<<" Celsius degrees";
      }

   return 0;
    }

 

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