GO Bananas

--Originally published at Programming

The instuction was:

What To Do

Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana”  (or “BANANA” ) is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.

kjhgfdsa


Babylonian method

--Originally published at Programming

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Before start, I recomend to look at this page, because well i didn’t know what is the babylonian method, so… if you don’t know, look this !

https://mathlesstraveled.com/2009/05/18/square-roots-with-pencil-and-paper-the-babylonian-method/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The instruction was:

What to Do

The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ10 on your post so our blog hub picks that up.

 

Here is my code:

Babylonian

#WSQ10

 


Final project

--Originally published at Programming

Well, we’re going to do a clock but…different. Is something like this.

Reloj-de-palabras

The team:

  • Estefanía Langarica
  • Karen Chacón
  • Angel

Our code is this:

#include <string.h>
#include <Wire.h>  
#include"RTClib.h"


                    // Display output pin assignments

#define MINUTES            Display1=Display1   | B00000001

#define MTEN   Display1=Display1   | B00000010  

#define HALF     Display1=Display1   | B00000100

#define PAST     Display1=Display1   | B00001000

#define THREE  Display1=Display1   | B00010000

#define ITIS        Display1=Display1   | B00100000

#define TWENTY      Display1=Display1   | B01000000

#define TO      Display1=Display1   | B10000000

 

#define TWO         Display2=Display2   | B00000001

#define SIX             Display2=Display2   | B00000010 

#define TWELVE         Display2=Display2   | B00000100

#define HFIVE    Display2=Display2   | B00001000

#define SEVEN  Display2=Display2   | B00010000

#define OCLOCK          Display2=Display2   | B00100000

#define ONE          Display2=Display2   | B01000000

#define QUARTER         Display2=Display2   | B10000000

 

#define EIGHT   Display3=Display3   | B00000001

#define MFIVE   Display3=Display3   | B00000010 

#define ARDUINO  Display3=Display3   | B00000100

#define ELEVEN Display3=Display3   | B00001000

#define HTEN    Display3=Display3   | B00010000

#define NINE     Display3=Display3   | B00100000

#define FOUR    Display3=Display3   | B01000000

#define RBK     Display3=Display3   | B10000000

 

int hour=0, minute=0, second=0;

static unsigned long msTick =0;  // the number of Millisecond Ticks since we last 

// incremented the second counter

int  selftestmode;          // 1 = in self test - flash display

char Display1=0, Display2=0, Display3=0;
                        

// hardware constants

int LEDClockPin=8;  // Arduino Pin#8 - Shift register 74HC595 Pin 11 clock

int LEDDataPin=9;   // Arduino Pin#9  - Shift register 74HC595 pin 14 Data

int 
Continue reading "Final project"

Multipart data and files

--Originally published at Programming

The instruction was:

So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). You will want to look at how to create/define and return a struct value from a function and how to open and read text files line by line.

ñlkjhgf


Yo soy 196

--Originally published at Programming

Background

Lychrel numbers are natural numbers that do not form a palindrome after successive additions to their inverse. See details on Wikipedia: http://en.wikipedia.org/wiki/Lychrel_number

The instruction was:

Your job is to create a program that asks the user for two pieces of data:
  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”.

Important

The report must show:
  • The range of numbers analysed (lower to upper bound)
  • The number of natural palindromes (no addition to inverse needed)
  • The number of non-Lycherels encountered (become palindromes)
  • The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

To get this working well, you will need support for Big Integers. You can base your solution off my codebase on GitHub. Unzip all of the files in a directory and use the command “make” to compile. Run the executable.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Videos that can help you:

Requests BigInteger and Make —-> https://www.youtube.com/watch?v=PHZYtOhFAZs

YoSoy196 Demo Run —-> https://www.youtube.com/watch?v=KMDDoipS9H0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jdbsadlkjh

 


Quiz #9

--Originally published at Programming

The instruction was:

Write a function that receives four parameters: x1, y1, x2, y2 which are all floating point values.

The function is called distance and returns (float) the distance between x1,y1 and x2,y2 on the cartesian coordinate plane.

Quiz #8

--Originally published at Programming

Fill out that survey here: http://url.kenbauer.me/midtermsurvey

The instruction was:

  • Write a function that calculates returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series. So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero. You should try to implement this with two solutions: one with a loop and one with recursion. Which do you think is “better”, which looks more “elegant”, which is more “efficient”?

 


Lists

--Originally published at Programming

The instruction was:

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

Important:

For the C++ group you can do this with arrays or Vectors, but you will need to know eventually how to do both.

Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

I looked this video: https://www.youtube.com/watch?v=MRqtXL2WX2M

So…here is my code!

list

#WSQ07

 


Factorial calculator

--Originally published at Programming

Well for this program ask me to do this:

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

Important things:

  • There are two basic approaches: a loop with an accumulator of the multiplication and a recursive solution. Choose one and implement that. Once that is done, try the other way.
  • If you used a while loop for the solution with a loop, try structuring this with a for loop (or vice-versa).

 

But what is a factorial?

The factorial function (symbol: !) means to multiply a series of descending natural numbers. Examples:

  • 4! = 4 × 3 × 2 × 1 = 24
  • 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040
  • 1! = 1

Let’s start!

factorial

Int64_t & long int

  • int64_t  is guaranteed by the C99 standard to be exactly 64 bits wide on platforms that implement it, there’s no such guarantee for a long which is at least 32 bits so it could be more.

#WSQ06


Quiz #6

--Originally published at Programming

Well in this quiz ask for various activities, so its good to practice.

Important things:

  • Note that you will also need to include <stdio.h>
  • printf will also complain that you are not passing an int to the %d so perhaps you want to cast the sizeof value to an int like this:

int(sizeof(c)*8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For the first exercise:

Type in the following program and run it:

#include 
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
	char c;  
	short s;  
	int i;  
	unsigned int ui;  
	unsigned long int ul; 
	float f;
	double d;  
	long double ld;  
	cout << endl 
  	     << "The storage space for each variable type is:"
	     << endl;
	cout << endl << "char: \t\t\t%d bits",sizeof(c)*8;  //  \t means tab 
	cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
	cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
	cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
	cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
	cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
	cout << endl << "double: \t\t%d bits",sizeof(d)*8;
	cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;

q61

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For the second exercise:

Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

	Input a single character, followed by : h
	Input an integer, followed by :  4872
	Input a float, followed by :  182.937
	The character h when cast to an int gives value ?????
	The character h when cast to a float gives value ?????
	The integer 4872 when cast to a char gives value ?
	The integer 4872 when cast to a float gives value ?????
	The float 182.937 when cast to a char gives value ?
	The float 182.937 when cast to an 
q62
q63
q64
q65
Continue reading "Quiz #6"