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

Tag Archives: #008800

#Quiz11

Here´s my quiz 11, it was a little more complicated than I thought, but in the end I receive some help from my friends Marco Patiño and Esaú Preciado, and well they teach me how to do the programms.

so here are my programms

q1.

 <iostream>
<iomanip>
using namespace std;

void newline(){
  cout<<endl;
}

double factor(int a){
double output= 1.0;
for (int i = 1; i <= a; i++){
  if (a == 0)
  return output;
  else
  output = output * i;
  }
return output;
}

double define_e(int exact){
double output1 = 0.0, output2 = 1.0;
for(int i= 1; i<1000 ; i++){
  output1 = output2;
  output2 = output1 + (1/factor(i));
}
cout << fixed << setprecision(exact) << output2 << endl;
return output1;
}
int x = 0;

int main(){
float e;
string z;
cout<<"Hi, I´m a calculator of the e constant "<<endl;
newline();
cout<<"Please insert how precisely you want this mathematical constant "<<endl;
newline();
cin>>e;
newline();
cout<<"The result equals to "<<define_e(e)<<endl;
newline();
}
return 0;
}

 

q2.

 <iostream>
<string>
<fstream>
using namespace std;

int main(){
string Read;
string Banana = "banana";
char archive[50];
int x = 0;
int y = 0;
int counter = 0;
cout << "Write the name of your file: ";
cin >> archive;

ifstream read_file (archive);
if (read_file.is_open()){
while (getline(read_file , Read)){
      x = 0;
      while (x < Read.length()) {
        char character = Read[x];
        if ( character == 'B' || character== 'b'){
          y = x + 1;
          char character = Read[y];

          if (character == 'A' || character== 'a'){
            y++;
            char character = Read[y];

            if (character == 'N' || character== 'n'){
              y++;
              char character = Read[y];

              if (character == 'A' || character== 'a'){
                y++;
                char character = Read[y];

                if (character == 'N' || character== 'n'){
                  y++;
                  char character = Read[y];

                  if (character == 'A' || character== 'a') {
                    counter++;
                  }
                }
              }
            }
          }
        }
        x = x + 1;
}

    }read_file.close();
    }else{
      cout << "Error 404 not found" << endl;
    }
cout << "I found " << counter << " bananas....So eat them all!!!...or not..." << endl;
return 0;
}

Also on github.

Program1.

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

Program2

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

#Project Advance 3

We finally did the project, we just need to adjust some functions, because we were using functions from theimagemagick library, tomorrow we´re going to change the programm and see if it runs with arrays.

here´s the code:

 <Magick++.h> 
<iostream>
using namespace std;
using namespace Magick;

void newline(){
  cout<<endl;
}

int main(int argc,char **argv)
{
  InitializeMagick(*argv);
  try{
  int x;
  cout<<"Hi, Im a manipulator of images "<<endl;
  newline();
  cout<<"What do you want to do? (press the number in your keyboard) "<<endl;
  newline();
  cout<<"1. Rezise the image to one half of its original size"<<endl;
  cout<<"2. Switch to black and white"<<endl;
  newline();
  cin>>x;
 
  if(x==1){
     newline();
     cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl; 
     newline();
     Image image;
     string img;
     cin>>img;
     image.read(img);
     image.minify();
     image.write("resized.jpg");
 }
  if(x==2){
     newline();
     cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl; 
     newline();
     Image image2;
     string img2;
     cin>>img2;
     image2.read(img2);
     image2.quantizeColorSpace( GRAYColorspace );
     image2.quantizeColors( 256 );
     image2.quantize( );
     image2.write("blackandwhite.jpg");
 }      
 }
  catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }
  return 0;
}

#Project Advance 3

This is not the final final project, and It´s not complete.

¡¡¡¡Hi!!!! this is the advance of the project, but we dont know how to change this to pixels or vectors, 

Link to code: 

https://github.com/kenwbauer/TC101F15_Team01/commit/62ff22fecfd823e3d4496eea9a7cdad78116c46d

 <Magick++.h> 

<iostream>

using namespace std; 

using namespace Magick; 

void newline(){

  cout<<endl;

int main(int argc,char **argv) 

  InitializeMagick(*argv);

  try{

  int x;

  cout<<"Hi, Im a manipulator of images "<<endl;

  newline();

  cout<<"What do you want to do? (press the number in your keyboard) "<<endl;

  newline();

  cout<<"1. Rezise the image to one half of its original size"<<endl;

  cout<<"2. Switch to black and white"<<endl;

  newline();

  cin>>x;

  if(x==1){

     newline();   cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl;  

     newline();

     Image image;

     string img;

     cin>>img;

     image.read(img);

     image.minify();

     image.write("resized.jpg");

 }

  if(x==2){

     newline();

     cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl;  

     newline();

     Image image2;

     string img2;

     cin>>img2;

     image2.read(img2);

     image2.quantizeColorSpace( GRAYColorspace );

     image2.quantizeColors( 256 );

     image2.quantize( );

     image2.write("blackandwhite.jpg");

 }       

 } 

  catch( Exception &error_ ) 

    {  cout << "Caught exception: " << error_.what() << endl;  return 1

    }return 0

}

 

#Project Advance 2

Hi everyone this is the “report” of the project.

This time we are using Imagemagick, Magick++; we can half size the image yeah, but we can’t change the color, ooooooooo u.u, so with this problem we are in a hurry, but we can do it and we feel positive with it because we are in the half of the way to complete this task 🙂

I feel like I´m not doing my best with this project, but here I am trying.

Some links that we found, (more Ever) and  this can help:

http://www.imagemagick.org/Magick++/Color.html#ColorGray

http://www.imagemagick.org/script/perl-magick.php

 

The code:

 

using namespace std;
using namespace Magick;

void newline(){
  coutendl;
}

int main(int argc,char **argv)
{
  InitializeMagick(*argv);
  try{
  int x;
  cout"Hi, Im a manipulator of images "endl;
  newline();
  cout"What do you want to do? (press the number in your keyboard) "endl;
  newline();
  cout"1. Rezise the image to one half of its original size"endl;
  cout"2. Switch to black and white"endl;
  newline();
  cin>>x;
 
  if(x==1){
     newline();
     cout"Alright, now introduce the name of the file with its extension; example: new.jpg"endl; 
     newline();
     Image image;
     string img;
     cin>>img;
     image.read(img);
     image.minify();
     image.write("resized.jpg");
 }
  if(x==2){
     newline();
     cout"Alright, now introduce the name of the file with its extension; example: new.jpg"endl; 
     newline();
     Image image;
     string img2;
     cin>>img2;
     image.read(img2);
     image.quantize(colorspace.gray);
     image.write("blackandwhite.jpg");
 }      
 }
  catch( Exception &error_ )
    {
      cout "Caught exception: " error_.what() endl;
      return 1;
    }
  return 0;
}

 

 

#Project Advance 2.

So, right now I technically push even forward my programming skills, I mean…using imagemagick is a little bit hard, but today I compile some code and it runs!!!

Marco and I manage to resize the image to one half of its original size, but now we´re struggling with the grayscale functions and stuff, at least we have something to keep working on and we feel positive about the results in our final project.

We find some useful functions in the following pages:

http://www.imagemagick.org/script/perl-magick.php

http://www.imagemagick.org/Magick++/Color.html#ColorGray

 <Magick++.h> 
<iostream>
using namespace std;
using namespace Magick;

void newline(){
  cout<<endl;
}

int main(int argc,char **argv)
{
  InitializeMagick(*argv);
  try{
  int x;
  cout<<"Hi, Im a manipulator of images "<<endl;
  newline();
  cout<<"What do you want to do? (press the number in your keyboard) "<<endl;
  newline();
  cout<<"1. Rezise the image to one half of its original size"<<endl;
  cout<<"2. Switch to black and white"<<endl;
  newline();
  cin>>x;
 
  if(x==1){
     newline();
     cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl; 
     newline();
     Image image;
     string img;
     cin>>img;
     image.read(img);
     image.minify();
     image.write("resized.jpg");
 }
  if(x==2){
     newline();
     cout<<"Alright, now introduce the name of the file with its extension; example: new.jpg"<<endl; 
     newline();
     Image image;
     string img2;
     cin>>img2;
     image.read(img2);
     image.quantize(colorspace.gray);
     image.write("blackandwhite.jpg");
 }      
 }
  catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }
  return 0;
}

The first option is the only one that works, we are going to keep working with the colors.

See you later!

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

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

}

 

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