#WSQ06

--Originally published at OlafGC / Class #TC1017

Long time no see you, guys. This is a blog post for the WSQ06, which is a factorial calculator. The tricky part is to write down the function, to understand the logic of the factorial numbers to teach it to the computer. I used a float because when you get the factorial of a big number things get pretty nasty for an int. And in the end, you just need to write a loop in case the user wants to run the program again (which we’ve already done dozens of times).

Code:

#include <iostream>
using namespace std;
float factorial(float n)
{
float result;
if(n>0)
result=n*factorial(n-1);
else if(n==0)
result=1;
return result;
}
main ()
{
float num, res;
char op;
do{
cout<<“Write the number you want to convert:”<<endl;
cin>>num;
res = factorial(num);
if(res==0)
cout<<“You cannot get factorials from negative numbers.”<<endl;
else{
cout<<“The factorial number is: “<<res<<“.”<<endl;
}
cout<<“Do you want to calculate another number? (y/n) “;
cin>>op;
if(op==’N’||op==’n’)
cout<<“Have a nice day!”<<endl;
else
cout<<“Let’s go again!”<<endl;
}
while(op==’Y’||op==’y’);
return 0;
}

 


#WSQ05

--Originally published at OlafGC / Class #TC1017

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

int sum(int n1, int n2)
{
return(n1+n2);
}
int dif(int n1,int n2)
{
return(n1-n2);
}
int pro(int n1, int n2)
{
return(n1*n2);
}
int divi(int n1, int n2)
{
return(n1/n2);
}
int mod(int n1, int n2)
{
return(n1%n2);
}

int main()
{
int n1,n2;
cout<<endl;
cout<<“This program gives you the sum, difference, multiplication, division and the remainder of two given numbers.”<<endl;
cout<<endl;
cout<<“Please insert the first number:”<<endl;
cin>>n1;
cout<<“Please insert the second number:”<<endl;
cin>>n2;
int s=sum(n1,n2);
int d=dif(n1,n2);
int p=pro(n1,n2);
int di=divi(n1,n2);
int m=mod(n1,n2);
cout<<“The result of the sum is “<<s<<“.”<<endl;
cout<<“The result of the difference is “<<d<<“.”<<endl;
cout<<“The result of the product is “<<p<<“.”<<endl;
cout<<“The result of the division is “<<di<<“.”<<endl;
cout<<“The remainder of the division is “<<m<<“.”<<endl;
return 0;
}


Talking Chalk/ OlagGC #FinalProject©

--Originally published at OlafGC / Class #TC1017

So here is the first post about our progress in the project. We have eight weeks left. We had two ideas: the first one consisted on assembling a robotic arm and program it; the second one, in making an app (for cellphone or computer) very similar to Duo-lingo, but instead of learning  new idiom, it will teach you C++. We thought it may be a great support tool (gamification) for learning how to program, helping students on their journey through  Solving Problems with Programming.

sin-titulo

***Update***

This is a link to the latest update of our SUPER ULTRA MEGA ADVANCED, GREAT AND POWERFUL INNOVATIVE PROJECT, a post made by me and The Talking Chalk

on his blog.


#WSQ04

--Originally published at OlafGC / Class #TC1017

WSQ04, the most challenging task so far (just kidding, they are all pretty easy. Even more if you have a friend’s help). Anyway, I’ll upload the video later, so you can see the whole process.

Code:

#include <iostream>
using namespace std;

int main()
{
int n1, n2, dif, sum, sum2, count=0, cicle;
cout<<endl;
cout<<“Give me two numbers and I’ll calculate the sum of the integer in that range.”<<endl;
cout<<endl;
cout<<“Please introduce the first number (the lower bound):”<<endl;
cin>>n1;
cout<<“Please introduce the second number (the upper bound):”<<endl;
cin>>n2;
dif=n2-n1;
cicle=dif;
sum=n1;
sum2=sum+1;
do
{
sum=sum+sum2;
sum2++;
count++;
}
while(cicle>count);
cout<<“The sum of the integers in that range is “<<sum<<“.”<<endl;
return 0;
}

Here’s the code working:wsq04


WSQ03

--Originally published at OlafGC / Class #TC1017

Pick a number!

This is it, the third program. This program needs a loop, in case the user wants to keep playing. You basically you just create it with a “do” and a “while”.  To generate the random number you have to include two libraries: “ctime” and “cstdlib”. I included some few modifications to the program Ken asked. If you need any help, just ask for it!

Code:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int guess, num, cont ;
string res;
cout<<endl;
cout<<“Try to guess the number I have in mind (between 1 and 100).”<<endl;
do {
srand(time(NULL));
num=1+rand()%(101);
cont=4;
cout<<“You have 5 oportunities to guess.”<<endl;
cout<<“Please insert your guess:”<<endl;
cin>>guess;
while(num!=guess && cont>0)
{
cont=cont-1;
if(guess>num)
{
cout<<“The number “<<guess<<” is too high, please try again.”<<endl;
cin>>guess;
}
else
{
cout<<“The number “<<guess<<” is too low, please try again.”<<endl;
cin>>guess;
}
}
if(guess!=num)
{
cout<<“Good luck next time my friend, the number was “<<num<<“.”<<endl;
}
else
{
cout<<“Congratulations! You guessed the number in just “<<5-cont<<” attempts.”;
}
cout<<“You want to try your luck again? Yes/No.”<<endl;
cin>>res;
}
while(res!=”no” && res!=”NO” && res!=”No”);
return 0;
}

wsq03


#WSQ02

--Originally published at OlafGC / Class #TC1017

The objective of this program is to convert temperature in Fahrenheit to Celsius, and will also tell  you the state of the water at that temperature. Here’s the code:

#include <iostream>

using namespace std;

int main ()
{
int f, c, w;

cout<<“Introduce the temperature in Fahrenheit and I will convert it to Celsius.”<<endl;
cout<<“I will also tell you the state of water at that temperature.”<<endl;
cin>>f;
c=5*(f-32)/9;
cout<<“The temperature in Celius is “<<c<<“.”<<endl;
if (c>=100)
{
cout<<“Water is at its boiling temperature.”<<endl;
}
else if (c==4)
{
cout<<“Water is at its maximum density.”<<endl;
}
else if (c<100 && c>0)
{
cout<<“Water is not yet at its boiling temperature.”<<endl;
}
else if (c<=0)
cout<<“Water is at its freezing temperature.”<<endl;
return 0;
}

WSQ02.png


Quiz#4

--Originally published at OlafGC / Class #TC1017

So today we did our fourth quiz, which consists on doing two functions, so there it goes. If you need help, there’s my twitter.

Code:

#include <iostream>
using namespace std;

int minimunThree(int x, int y, int z)
{
if (x<=y && x<=z)
{
return x;
}
else if (y<=x && y<=z)
{
return y;
}
else if (z<=x && z<=y)
{
return z;
}
}

int sumSquares(int x, int y, int z)
{
return (x*x + y*y + z*z);
}

int main ()
{
int a, b, c;
cout<<“This program will tell you which number is the smallest out of three, and the sum of its square.”<<endl;
cout<<endl;
cout<<“Please insert the first number:”<<endl;
cin>>a;
cout<<“Please insert the second number:”<<endl;
cin>>b;
cout<<“Please insert the third number:”<<endl;
cin>>c;

int min= minimunThree(a,b,c);
int sum= sumSquares(a,b,c);

cout<<“The smallest number is: “<<min<<“.”<<endl;
cout<<“The sum of the square of those three numbers is: “<<sum<<“.”<<endl;
return 0;
} //Enrique Olaf García Cambero

quiz04


My first program:

--Originally published at OlafGC

Well, here it is: my first C++ program. I have to admit it; the most difficult part to me was to find how to open the damn file, but after searching for an entire half hour how to find it, I finally did it.  The program is quite simple (of course, it’s the first one), but so far I’ve noticed that C++ is not by far as simple as C#, which I learned last semester in Remedial. Anyway, here’s the code. I offer my help to anyone that might need it (you can find my twitter on the contact button).

#include <iostream>
using namespace std;
int main()
{
 cout<<“Hello world.”<<endl;
return 0;
}

hello-world-foto


Surprise surprise… Quiz#3 (corrected)

--Originally published at OlafGC

(This post is edited and has the correct and ultimate version of the code at the very end, with a new entry)

Do you feel like you want to burn your computer to ashes each time your code is not compiling because of a simple “;”? Am I the only one, for real?

quiz3-problema

Yes, today we had a quiz (and I wasn’t there, to make it worse). The quiz consists on making a program that will give you the square and cubic root of any number you plug into it. Pretty easy concept…  if you have read at least to chapter 3 in your book.

I’m presenting this quiz at this hour because I know that I acquired the knowledge required, and to me it’s all that matters. I did not just copied a piece of code from another partner.

After a freaking lot of few mistakes, my program runs correctly, so here it goes, photo and text code:

#include<iostream>

#include <cmath>//this for including the math library for functions
using namespace std; //automatically gives a space after finishing each line
//You have to tell the computer what are the variables(declare them) and assign an operation
double square_root(double number)
{
return sqrt(number);
}
double cubic_ro

ot(double number)
{
return cbrt(number);
}
//Once you’ve declared all variables, you start writing the “visible code” (term made up by myself)
int main ()
{
int number;
double resquare, rescubic; //Name the variables you declared before
cout<<“I will give you the square and cubic root of any positive number you give me:”<<endl; cin>>number;
if(number>0) //here we set the condition a number must accomplish in order to be solved
{
resquare – square_root(number);
cout<<“The square root of that number is ” <<resquare<< cout<<“.”<< endl; //nice and tidy
rescubic – cubic_root(number);
cout<<“The cubic root of that

quiz3-alfin
quiz31
Continue reading "Surprise surprise… Quiz#3 (corrected)"

WSQ 01

--Originally published at OlafGC / Class #TC1017

Here you have it… WSQ 01. The program is very simple: You give the computer 2 numbers and the computer do different operations with them. In this program, there is no need to add additional libraries, you just use <iostream>. So here’s the code and how it works. If you have any questions, you can contact me in the twitter link on top of my blog.

Code:

#include <iostream>

using namespace std;

int main()
{
int n1, n2, sum, dif, pro, divi, rema;
cout<<“Give me two numbers and I’ll calculate its sum, difference, product, division and remainder from division.”<<endl;

cout<<“Give me your first number:”<<endl;
cin>>n1;
cout<<“Give me your second number:”<<endl;
cin>>n2;
sum=n1+n2;
cout<<“The result of the sum is “<<sum<<“.”<<endl;

dif=n1-n2;
cout<<“The result of the difference is “<<dif<<“.”<<endl;

pro=n1*n2;
cout<<“The result of the product is “<<pro<<“.”<<endl;

divi=n1/n2;
cout<<“The result of the division is “<<divi<<“.”<<endl;

rema=n1%n2;
cout<<“The remainder of the division is “<<rema<<“.”<<endl;
return 0;
}

wsq01