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

Tag Archives: #ffffff

#WSQ09 Factorial

 

Factorials

In this WSQ I used the factorials, and what is that? you maybe are asking, this is a factorial: 

 

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal ton. For example,

5! = 5  times  4  times  3  times  2  times  1 = 120.

And I´m here, yeah, you can ask me whatever about it, if I don´t know maybe I can talk with my classmates and help you, you little human, jajaja :).

 

 <iostream>

<cmath>

 using namespace std;

int main(){

    int num, factorial= 1;

cout<<"Enter number to find it´s factorial: ";

cin>>num;

for (int a=1; a<= num; a++)

{

factorial= factorial*a;

}

cout <<"The factorial is:  over 9000 "<<endl; 

cout <<"Na, I´m joking, this is the real:  "<<factorial<<endl;

cout<<"Thanks for visiting us, see you "<<endl;

return 0;

}

 

Github link (This dark place where I save all my programs if you want, take a look over here):

 https://github.com/MarAnMu13575/-WSQ09-Factorials/tree/master

#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.
}

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


 }

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

 

#WSQ03-Fun with Numbers

Look!! I´ve learned how to use variables in a programm.

At first it was kinda difficult, but after a few trys and a session of watching video in internet I finally figure it out how to do simple aritmetical operations in c++.

i´ve been playing aroun with the language, and I know that you need to follow these essential aspects:

-Initialize the variable

-Assign a value to the variable (or ask the user to introduce one).

-Make operations with the names of the variables (not the values).

Those are the basic steps that  I found useful in the topic.

 

Here is my code.

 

 

#include <iostream>
using namespace std;

int main(){

int x;
int y;

cout<<"Hello, I´m a calculator of two values"<<endl;
cout<<""<<endl;
cout<<" give me the first value"<<endl;
cout<< ""<<endl;
cin>>x;

cout<<" give me the second value"<<endl;
cout<<""<<endl;
cin>>y;

int z=y-x;
cout<<"The addition equals to  ";
cout<<z<<endl;

int c=y+x;
cout<<"The substraction equals to  ";
cout<<c<<endl;

int d=y*x;
cout<<"The multiplication equals to ";
cout<<d<<endl;

int a=y/x;
cout<<"The division is equals to  ";
cout<<a<<endl;

int b=y%x;
cout<<"The res equals to ";
cout<<b<<endl;


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