Class Review 2017

Ken’s classes are way different than normal classes in Tec. The purpose of his course is for the student to learn by himself and also to know the basics of programming on C++. One day I had a question about my code and he simply answered «C’mon, just google it». If you can’t solve it on your own, then he will be happy to help. What caught my attention of his classes is that every assignment, quiz or partial exam does not have a value. Instead, we have to fill up a rubric but if you think that you deserve more points you are free to put your own grade. In the end, Ken will check that grade and if he disagrees he will tell you.

Overall my personal experience in this class was great. Since I did not manage well my time on this semester, I used some of his classes to complete other assignments and I made the WSQs in my house. When I had a doubt, I just simply waited for the other class to come in order to ask Ken. If you are new to his class you must know that his favorite number is 42 and his favorite word is banana, he likes to give examples with them.

The most important tools that Ken’s courses will give you is the ability to learn by yourself and also to be curious about a topic you are interested. His method of teaching proves that students can learn a lot even without pressure.

 

Find Bananas

#WSQ11

This program reads the «data.txt» file and tells the user how many times it says banana in there.

The only problem with my code is that bash detects an error  on line.lenght, if anyone knows how to solve it be free to comment down below.

Here is the program:

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

//This function opens the assinged .txt, opens it and
int find_banana(string filename) {
string line;
int banana=0;
ifstream file(«data.txt»);
if (file.is_open()); {
while (getline(file, line)) {
for (int i=0; i<line.lenght(); i++) {
line [i] = tolower(line[i]); //Changes all letters to lower case
}
int search=line.find(«banana»);

while (search>=0) {
banana++;
search=line.find(«banana»,search+1);
}
}
}
return banana;
}

int main () {
cout << «Banana is writen in that text » << find_banana(«data.txt») << «times.» << endl;
return 0;
}

References: http://www.cplusplus.com/reference/fstream/ifstream/is_open/

http://www.cplusplus.com/reference/string/string/getline/

http://www.cplusplus.com/reference/cctype/tolower/

SciLab

#WSQ13

This program is only for mathematical purposes. It works using a c++ kind of language. I saw the guide and discovered that with this program you can create charts and also use vectors. I tried the program to only put simple mathematical operations. Some complex expresions are like in c++, pow and sqrt. I think that this program will help me in the future, i’ll keep it on my laptop untill then.

Estimating «e»

#WSQ12

This program asks the user for the number of decimal points of accuracy and then gets euler’s number with that specification.

The most difficult part of this program was to understand how the euler’s number is calculated. I discovered that there are two methods to find it so i chose the one that for me was easier. I also had problems with my code because I was using «long «and «int» and in the end i discovered that I really needed the «double».

Sources:

https://www.thoughtco.com/definition-of-double-958065

http://www.mathsisfun.com/numbers/e-eulers-number.html

Screenshot (99)Screenshot (100)

Final Project (Calculator)

#Project

Raul and me decided to make a calculator as a final project. We were very busy on the final’s week but we managed to complete it. This code gives the user two options, work with one number or two. It then displays all of the operation a calculator can do and the user selects the option he wants. In the end, it displays the answer and asks the user if he would like to use the calculator again.

We used functions for the program to be cleaner. We had many errors when we wanted to include the function ln(n), so we decided not to include it.

Here is the code:

GitHub: https://github.com/antoniogh9/Calculator-Project/blob/master/calculator.cpp

Multipart Data and Files

#WSQ09

This program reads the characters and lines that are inside a file .txt

This program was very useful because i learned how to open an external file using code. I didn’t knew that a program was able to read a file and get results from it.

 

GitHub: https://github.com/antoniogh9/WSQ-09_MultipartDataandFiles/tree/master

References:

https://gehrcke.de/2011/06/reading-files-in-c-using-ifstream-dealing-correctly-with-badbit-failbit-eofbit-and-perror/

Screenshot (61)

Babylonian Method

#WSQ10

This program was way easier than WSQ08.

The purpose of this program is to find the square root of a value given by the user using the Babylonian method.

Here is the code:

#include<iostream>
#include<cmath>
using namespace std;

float babylonian_square(float a) {
float ans, b=0, dif=0;
ans = a/2;
do {
b = ans;
ans = (ans+a/ans)/2;
dif=b-ans;
} while (dif>0.001);

return ans;
}

int main() {
int val;
cout << «Enter your value: «;
cin >> val;
cout << «The square root of that number is » <<babylonian_square(val) << endl;
return 0;
}

GitHub: https://github.com/antoniogh9/WSQ-10_BabylonianMethod/blob/master/LICENSE.md/LICENSE.md

Resources

https://www.deltacollege.edu/dept/basicmath/Babylonian.htm

Lychrel Number

#WSQ08

Finally it’s done! But without the «BigIntegerLibrary.hh», I didn’t understanded how to add a library to my code. I’ll later submit this WSQ using that library but I must move on to the next WSQ.

This program asks the user for a lower and higher bound value and tells them which numbers are Lychrel, natural palyndrome and the non-lychrel that become palyndromes.

The only error that this program has is that it prints two times the Lychrel’s candidates, If anyone knows how to solve this problem be free to comment the solution.

#include <iostream>
using namespace std;

//To make the reversed number
long long swap(long long val) {
long long changed=0;

while(val>0) {
changed=(changed*10)+(val%10);
val=val/10;
}
return changed;
}

int LychrelConver(long long val) {
long long add;
int resp, tries=0;

if(val==swap(val)) {
resp=1;
} else {
add=val+swap(val);

while(tries!=30 && add!=swap(add)) {
add=add+swap(add);
tries+=1;
}

if(tries==30) {
resp=2;
cout << «Lychrel candidate is » << val << endl;
} else {
resp=3;
}
}
return resp; // The output of this function is either 1, 2, or 3.
}

int main() {
int high, low, lychrel=0, first=0, moreTries=0, resp;
long long val;
cout << «Give the lower bound of the range of numbers:» << endl;
cin >> low;
cout << «Give the upper bound of the range of numbers:» << endl;
cin >> high;

val = low;

for(int i=0; val!=high; i++) {
val = low + i;
if(LychrelConver(val)==1){
first += 1;
} else if(LychrelConver(val)==2) {
lychrel += 1;
} else {
moreTries += 1;
}
}

cout <<«\x1b[31;1m» << «Lychrel’s » << lychrel << endl;
cout << «Natural palindrome » << first << endl;
cout << «More tries palindromes » << moreTries << «\x1b[0m\n» << endl;

return 0;
}

GitHub: https://github.com/antoniogh9/WSQ-8_LychrelNumber/blob/master/README.md

References

https://codescracker.com/cpp/program/cpp-program-palindrome-

https://en.wikipedia.org/wiki/Palindromic_number

https://en.wikipedia.org/wiki/Lychrel_numbernumber.htm

https://stackoverflow.com/questions/20608058/c-colour-console-text

ERROR

I’ve been making the WSQ08 for a long time and it still does’t work as i expect. I’m stuck on this program and to be honest i’m also tired. I think i’m going to start making WSQ09 and come back later to see if I can think of anoher solution.

When we, the students, complain about programing I think that Ken’s reaction is this one:

eb374da5ef2d8ebfb6b6a624f852986d0656ee580626a8b393ce39a6456a0c6a