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

Tag Archives: #ffffff

#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

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

 

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