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

Tag Archives: #008800

#QUIZ07

When I first look at the Quiz, I didn´t know what to do, but with some research and using the string library I realize how to write the code and eventually, compile and run it.

The first programm is the one that calculates the fibonacci of a given position number, it was way difficult than I thought, but it the end…it works just fine.

 <iostream> //Ever Ibarra Almaral TC1017
using namespace std;

long fibonacci(long n){
  long x;
      if (n<=1){
      x=n;
      return x;
  }
      else{
      if(n>1){
          int y=0;
          int z=1;
          long temp;
          for(int i=1;i<n;i++){
      temp=y+z;
      y=z;
      z=temp;
    }
    return z;}
  }
  }

  void newline(){
    cout<<endl;
  }
  int main () {
    long a;
  cout << "Hello, I´m a calculator of fibonacci algorithm";
  newline();   newline();
  cout << "Please, enter the position of the number in the fibonacci algorithm: ";
  cin >> a;
  newline();
  cout << "The fibonacci number is: " << fibonacci (a);

  return 0;


}

https://github.com/everibarra/TC101-C-/blob/master/PROGRAMM%201%20QUIZ07

The second programm deals with strings in order to check if the word is a palindrome or not.

 <iostream> //Ever Ibarra Almaral TC1017
<string>
using namespace std;

string palindrome(string a){

a=string(a.rbegin(), a.rend());
return a;
}

void newline(){
  cout<<endl;
}

int main(){
  string b;
  cout<<"Enter the string "<<endl;
  cin>>b;
  newline();
  cout<<"the reverse string equals to "<<palindrome(b);
newline();
  if (b==palindrome(b)){
    cout<<"The string is a palindrome"<<endl;
    newline();
  }
  else{
    cout<<"The string its not a palindrome"<<endl;
    newline();
  }

  return 0;
}

https://github.com/everibarra/TC101-C-/blob/master/PROGRAMM%202%20QUIZ07

 

#WSQ10 Lists

Lists

 

In this wsq I had to do a program where the user had to input 10 numbers whatever and the program have to give him the total of the addition of all the numbers, average and standard deviation of those numbers. Every time I feel this like, ooh look I´am a c++ function, use me but I ´m not going to tell you how to use me so, teach by yourself loser, and I´am like, 🙁 okay (cries in spanish), but this like my teacher said,: It´s not difficult, you only have to remember each one and what they do, and I ´am like 🙁 okay, but kids don´t mess with c++, if you do, maybe it can beat you.

Link to my acount of github:https://github.com/MarAnMu13575/-WSQ10-Lists/tree/master

Links where I found information about the topic:  

http://www.cplusplus.com/reference/list/list/

http://www.cplusplus.com/reference/list/list/

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

The code:

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

float aver(float x){
  return (x/10);
}

int main (){
	float array1[10];
	float suma=0;
	float square=0, deviation;
	for (int i=0; i<10; i++)
	{
		cout<<"Introduce an value, and be gentle:  "<<(i+1)<<" : "<<endl;
		cin>>array1[i];
	}

	for (int i=0; i<10; i++)
	{
	suma+=array1[i];
	square+=(array1[i])*(array1[i]);
	}
	deviation=sqrt(square/10);
	cout<<"The addition is equals to: "<<suma<<endl;
	cout<<"The average of the numbers you introduce is: "<<aver(suma)<<endl;
	cout<<"The standard deviation of the numbers you introduce is: "<<deviation<<endl;

return 0;
}

 

15 cute postals for your enemy: http://9gag.com/gag/apB80jE (This is 9gag, this is fun)

 

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