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
Ever Ibarra Almaral’s Articles at TC101 Fall 2015, Page 2
Introduction to Programming Python and C++

Author Archives: Ever Ibarra Almaral

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

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

#Mastery2 and #Mastery13

For this mastery I download DEV C++ , which is a IDE that contains several useful tools, here in the description I´ll leave the link where I download it.

Here´s the video:

https://www.youtube.com/watch?v=7kT7fHPkwvQ

Here´s the link:

http://sourceforge.net/projects/orwelldevcpp/

#Mastery4 and #Mastery25

In this mastery, I explain how to use strings and the basic functions that can be applied to strings and also how to submit your work via github and blogpost.

here´s the video:

https://www.youtube.com/watch?v=S6jy-plr3kY

 

 

 

#Mastery19 and #Mastery20

Using loops is essential in a programming language, for and while are practical functions in c++, thats why this mastery talks about how useful they can be.https://www.youtube.com/watch?v=zHK4OjJVr8E

#Mastery11 and #Mastery12

These were easy masteries, because they´re basic to move forward into advance topics.

here´s the video:

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

#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

 

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