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 2
Introduction to Programming Python and C++

Tag Archives: #include

#WSQ13

This wsq was easier than i thought, first I search hoe to use the babylonian method in youtube, so I found these two videos about it:

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

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

After I analyze the video in detail I finally figure it out how to make a functional .cpp programm in any editor.

Babylonians were freaking smart! in school, teachers never taught me how to calculate the sqrt of a number without a machine, but now…I totally get it!

Here´s my code:

 <iostream>
using namespace std;

double babylonian(double number) {
 double failure= 0.00001;
 double x= number;
 while((x - number/x) > failure) {
 x = (x + number/x)/2;
 cout<<"The intermediate result is " << x <<endl;
 }
 return x;
}

void newline(){
  cout<<endl;
}

int main() {
 double num;
 cout<<"Hi, I´m a calculator of the square root of a number using the babylonian method"<<endl;
 newline();
 cout<<"Introduce the number "<<endl;
 newline();
 cin>>num;
 double result = babylonian(num);
 cout<<"The square root of "<<num<<" equals to "<<result<<endl;

 return 0;
}

Here´s my code on github:

https://github.com/everibarra/TC101-C-/blob/master/wsq13.cpp

#WSQ12

This wsq was pretty easy, I mean, by following the Euclidean Algorithm you can easily know the greatest common divisor between two values

Here´s a video that help me out when I was trying to understand how to use the principles of Euclid.

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

Also, I need to mention that I receive some more help, because I search for similar codes in the web, and here´s what I found to complete my task.

https://github.com/carolinarmtz/TC1017/blob/master/WSQ12.cpp

And here´s my code:

 
using namespace std;

void newline(){
  coutendl;
}

int common(int first, int second)
{
	if (first==second)
	{
		return first;
	}
	else if (first>second)
	{
		return common(first-second, second);
	}
	else
	{
		return common(first, second-first);
	}
}

int main ()
{
	int x,y;
  cout"Hello, I´m a calculator of the greatest common divisor from two numbers. "endl;
  newline();
  cout"Enter the first number."endl;
  newline();
	cin>>x;
  newline();
  cout"Enter the second number. "endl;
  newline();
  cin>>y;
  newline();
	cout"The greatest common divisor from "x" and "y" is "common(x,y)endl;
	return 0;
}

#Mastery 12 TC1017

Crear Funciones en C++
Crear una función es fácil. El proceso para crear una es el siguiente:
1- Se programa la unción
2- Se define la función
3- Se utiliza la función en el programa principal.
Su estructura es la siguiente:
Por ejemplo:
using namespace std;
int factorial(int a){
int cont, act = 1;
for (cont =1; cont)
{
fact = fact*cont;
}
return fact;
}
int main(){
int num1;
int resultado = factorial (num1);
cout
cin num1;
cout
return 0;
}

#WSQ11

First of all, this was a difficult WSQ, I receive a lot of help from Marco Patiño, but I think I just do it right, so thanks Marco!!!

 
 
 #include "BigIntegerLibrary.hh"
  using namespace std;
   bool is_palindrome(BigInteger n) {
   string s = bigIntegerToString (n);
    reverse (s.begin(), s.end());
     BigInteger bi = stringToBigInteger (s);
      if (n == bi) {
      return true;
       }
        else {
        return false;
        } }
         BigInteger apply196(BigInteger n) {
         string s2 = bigIntegerToString (n);
         reverse (s2.begin(), s2.end());
         BigInteger bi = stringToBigInteger (s2);
         n = n + bi; return n;
         }

         int main() {
         int lb;
         int up;
         int np = 0;
         int nl = 0;
          int l = 0;
           BigInteger bn;
           cout  "Write the lower bound: ";
           cin >> lb;
           cout  "Write the upper bound: ";
           cin >> ub;
            cout  endl;
            for (int i=lb; iub; i++) {
            if(is_palindrome(i)==true) {
            cout  "This number is a natural palindrome"  endl; np++;
            }

            else {
            bn = apply196 (i);
            for(int j=1; j30; j++) {
            if(is_palindrome (bn)==true) {
            cout  "This is a non-Lychrel number"endl;
            nl++;
            break;
            }

            else {
             bn = apply196 (bn);
              } }

               if (is_palindrome(bn) == false){
                cout"This is a Lychrel number"endl; l++; coutendl;
                 } } }

                 cout  endl;
                 cout  "Analysis Report: "  endl;
                 cout  endl;
                 cout  "Number of Values Analyzed: "  (ub-lb) + 1  endl;
                 cout  "Number of Natural Palindromes: "  np  endl;
                 cout  "Number of Non-Lychrel Numbers: "  nl  endl;
                 cout  "Number of Lychrel Numbers: "  l  endl; return 0; }

Vectors and Arrays #Mastery23 #Mastery24

Vectors and Arrays are important tools to store a determined or undetermined quantity of values for further use. They will be developed during this post.

Vectors can store a determined set of values, initialize the values or assign them further in the code. Here are the several ways of using vectors. 

First a vector could be initialized as:

                vector Name (Number of values);

This will create a vector containing a certain type of data (which could be strings, integers, floating points, among others). The number of values will be the available spots within the vector. After the initialization each spot could be filled with a value by making reference to it. For example, in a vector which name is MyVector with 2 spots, values could be assigned by typing this:

               MyVector[0]= 0;

               MyVector[1]= 100;

Note: remember that the first spot within a vector is number 0.

Another way of initializing values would be:

               vector Name (Number of values, 5);

This would give each spot within the vector a value of 5 or any number after the comma. Also it can be done as:

                vector Name = {1,2,3,4,5};

which would create a vector with 5 spaces filled by the numbers written, in this case: 1,2,3,4,5.

A feature of the vectors is that you may obtain the number of spots within a vector by using the funtion size(), which would be used as: MyVector.size();

In case an additional space is required a new spot could be assigned by using the function push_back(), used as: MyVector.push_back(Value);

Finally, you may use the value within a vector for any task required, by calling them by typing the name of the vector and the spot. Which would be: MyVector[0], and would return the value in the first spot of the vector.

Here’s a code that uses a vector and its different functions to return the sum of the squares of given values:

        

Note: In order to use a vector and its commands, you should incude the vector library by starting the code with:

Arrays are simplier but with several disadvantages. The structure of an array might be:

type Name [Number]; 

Type would be any type of data such as strings, integers or floating points. Name any name you wish to assign to the array and finally the number of available spots within the array. A disadvantage of the arrays is that they have a fixed number of values that can not be modified as in the vectors. A direct initialization might also be possible by typing:

type Array [5] = {1,2,3,4,5};

Which creates an array called Array containing 5 values: 1,2,3,4,5. As in vectors, arrays can also be called and modified. For example:

Array[0]= Array[0]+2;

which changes the value of the array 0 which was 1 and turns it into 3.  

An interesting feature of arrays is the possibility of using multiple dimensions of the array. For instance, if we want to create a bidimensional array of integers we have to type:

int Array [n][m];

n and m stand for any integer value.

In order to understand easier this concept, we might think it as a row and column arrangement with coordinates to call each value. This image might help you visualize the concept:

Image Source: http://www.findmemes.com/c-memset-2d-array

Both turn useful if you intend to use several values and interact with them. The one you use depends on the task requested and on your personal preference if its a limited number of values, else you should use a  vector.

Hope this have helped you with this concepts. Thanks for browsing!

#Quiz08

This was a difficult quiz for me, at first I didn´t know how to use arrays so I decide to use vectors, in the end..IT WORKS!!!!

 <iostream>
<vector>
using namespace std;

void newline(){
  cout<<endl;
}

double sumsquares_list (vector<double> vector){
  double a = vector.size();
  double sum=0;
  for(double i=0; i<a; i++){
    sum=sum+(vector[i]*vector[i]);
  }
  return sum;
}

int main (){
  double x;
  vector<double>vector (0, 4); //You assign a size for your vector.
  cout<<"Hi, I´m a calculator of the addition of squares of the numbers you´ll give me "<<endl;
  newline();
  cout<<"introduce the number (to stop introducing numbers write-->-42)"<<endl;
  newline();
  cin>>x;
  newline();
  while(x!=-42){
    newline();
    cout<<"introduce the next number "<<endl;
    newline();
  vector.push_back(x); //You´re increasing the size of the vector
  cin>>x;
  }
  cout<<"The result equals to "<<sumsquares_list(vector)<<endl;
  return 0;
}

 Here´s my code

https://github.com/everibarra/TC101-C-/blob/master/Q8.cpp

avance

 <iostream>

<math.h>

using namespace std;

 

int sumsquares_list(int array1[]){

 

for (int i=0; i<5; i++){

int sum=0;

int square=0;

int array1[i];

square=(array1[i]*array1[i]);

}

return square;

}

 

int main(){

int array1[5];

for (int i=0; i<5; i++)

    {

        cout<<"Introduce the numerical value "<<(i+1)<<" : "<<endl;

        cin>>array1[i];

    }

 

cout<<"The result equals to "<<sumsquares_list(square)<<endl;

 

return 0;

}

 

#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

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