QUIZ 2

This quiz was also separated into two parts… the first one is able to ask for two different numbers to the user and calculate with a power function, the first number to the power of the second number.

//CODE 1:

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

int main(int argc, char const *argv[]) {
int num1, num2, R;
std::cout << “This program makes the power function between number 1 and number 2.” << std::endl;
std::cout << “Please enter number 1” << std::endl;
std::cin >> num1;
std::cout << “Please enter number 2” << std::endl;
std::cin >> num2;

R=pow (num1, num2);

std::cout << “The final result is… ” <<R << std::endl;
return 0;
}

Captura de pantalla 2016-02-17 a las 19.14.53

This code is able to print a certain number of stars with a value given by the user. Using a function called “stars” and a loop.

//CODE 2:

#include <iostream>

using namespace std;

void stars(int s) {
int count=0;
do {
std::cout << “*” << std::endl;
count++;
} while(count!=s);
}

int main(int argc, char const *argv[]) {
int s, count;

std::cout << “This program prints the stars you ask for.” << std::endl;
std::cout << “Please enter the number of stars you want to print in the console.” << std::endl;
std::cin >> s;
stars(s);

return 0;
}

Captura de pantalla 2016-02-17 a las 19.16.49

QUIZ 1

Quiz 1 was divided in three programs… the first one is able to determine the volume of a cylinder… the second one is able to calculate some basic operations (without using functions)… and the third one is basically similar to the second one but with more basic operations.

//CODE 1:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
float radius, height, volume;

std::cout << “This program can determine the volume of a cylinder.” << std::endl;
std::cout << “Please enter the value of the radius of the cylinder.” << std::endl;
std::cin >> radius;
std::cout << “Please enter the height of the cylinder.” << std::endl;
std::cin >> height;
volume=(3.1415*(radius*radius)*height);
std::cout << “The volume of the cylinder is “<<volume << std::endl;

return 0;
}

Captura de pantalla 2016-02-17 a las 19.09.49

//CODE 2:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
int n1, n2, r1, r2, r3;
std::cout << “This program can determine the product, integer division and the remainder of two random numbers.” << std::endl;
std::cout << “Please enter the first number.” << std::endl;
std::cin >> n1;
std::cout << “Please enter the second number.” << std::endl;
std::cin >> n2;
r1=n1*n2;
r2=n1/n2;
r3=n1%n2;
std::cout << “The product of the two numbers is… “<<r1 << std::endl;
std::cout << “The integer division of the two numbers is… “<<r2 << std::endl;
std::cout << “The remainder of the two numbers is… “<<r3 << std::endl;
return 0;
}

Captura de pantalla 2016-02-17 a las 19.10.49

//CODE 3:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
float n1, n2, r1, r2, r3, r4;
std::cout << “This program can determine the product, integer division and the remainder of two random numbers.” << std::endl;
std::cout << “Please enter the first number.” << std::endl;
std::cin >> n1;
std::cout << “Please enter the second number.”

Captura de pantalla 2016-02-17 a las 19.11.32

Continue reading “QUIZ 1”

#WSQ09-Factorial calculator

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

This where my instructions. And this is how I what I did.

This program accepts a “n” positive number and multiplies it in a sequence for example: 5!=102, this is also 1 x 2 x 3 x 4 x 5=120.

Also this program has a loop that ends with the sequence of the multiplications.

//CODE:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
int n, n2, conta;
char ans;
std::cout << “This program prints the factorial of <n> number.” << std::endl;
do {
std::cout << “Please enter a non-negative number to calculate the factorial.” << std::endl;
std::cin >> n;
if (n==0) {
std::cout << “The factorial is… 1” << std::endl; //cuando corro el programa sale factorial is… 1 y después factorial is… 0 y despues vulve a preguntar….
}
conta=n;
do {
conta=conta-1;
n=n*conta;
} while(conta !=1);
std::cout << “The factorial is… “<<n << std::endl;
std::cout << “Do you like to add another factorial? Write <y> for yes and <n< for no” << std::endl;
std::cin >> ans;

} while(ans==’y’);

return 0;
}

Captura de pantalla 2016-02-17 a las 18.58.58

#WSQ08-On to functions

Hey world…

In this WSQ I had to go back to the WSQ03 and yes is the same but the difference with this one, is that now the code has functions out of the “main” and I learnt how to create th synthesis of a function in C++.

You will go back and do WSQ03 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate.

//CODE:

#include <iostream>
using namespace std;

int difference(int a, int b) {
return(a-b);
}
int product(int a, int b) {
return(a*b);
}
int integerdiv(int a, int b) {
return((int)(a/b));
}
int residue(int a, int b) {
return(a%b);
}

int main(int argc, char const *argv[]) {
int x, y, d, p, i, r;

std::cout << “This program is similar to WSQ03, but now with functions.” << std::endl;
std::cout << “Please enter number 1.” << std::endl;
std::cin >> x;
std::cout << “Please enter number 2.” << std::endl;
std::cin >> y;
d=difference(x, y);
p=product(x, y);
i=integerdiv(x, y);
r=residue(x, y);
std::cout << “The difference is… “<<d << std::endl;
std::cout << “The product is… “<<p << std::endl;
std::cout << “The integer division is… “<<i << std::endl;
std::cout << “The residue is… “<<r << std::endl;
return 0;
}

This are all the functions I created.

And this is how they are called into the “main”.

Captura de pantalla 2016-02-17 a las 18.49.12

#WSQ7-Sum of numbers

This code was easy as I remember!! Also just a little of research in formulas to be able to complete it.

I wrote a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

I did use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

x=(n*(n+1))/2;

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

//CODE:

#include <iostream>

using namespace std;

void sumofnumbers(int n) {
int R=0;
R=(n*(n+1))/2;
std::cout << “The sum of the range is… “<<R << std::endl;
}

int main(int argc, char const *argv[]) {
int n, R;
std::cout << “This program sum the rage of numbers from the enter one.” << std::endl;
std::cout << “Please enter a number to sum its range.” << std::endl;
std::cin >> n;
sumofnumbers(n);

return 0;
}

Captura de pantalla 2016-02-17 a las 18.46.37

#WSQ06-Pick a number

This one was a little tricky, because I had to do some research of certain commands for it to properly run…

I made a program that picks a random integer in the range of 1 to 100.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You will see that I did use some “if ” conditionals just for simple logical problems and also I did use another helpful tool in C++ called “do-while”, what this command does is that repeats in loops the command inside the “do instructions” until the “while condition” (which is also a logical statement) is true or false depending on your code.

//CODE:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(int argc, char const *argv[]) {
int n1, n2, count=0;

std::cout << “This program can help you guess the number is picked.” << std::endl;
srand(time(NULL));
n1=rand()%100+1;
do {
count++;
std::cout << “Enter a number from 1 to 100.” << std::endl;
std::cin >> n2;
if (n2<n1) {
std::cout << “The number you just wrote is too low. Try again.” << std::endl;
}
else{
if (n2>n1) {
std::cout << “The number you just wrote is too high. Try again.” << std::endl;
}
else{
std::cout << “Congratulations you just hit the big one!!” << std::endl;
}
}
} while(n2!=n1);
std::cout << “You tried “<<count<<” time(s)” << std::endl;

return 0;
}

Captura de pantalla 2016-02-17 a las 18.35.17

#WSQ05-Temperature

Hey guys since I have already told you I am catching up!!…

What I had to do for this #WSQ05 well is simple… I made a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given.

This is what i did…//Code starts from next line

//CODE

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
float fa;
int cel;

std::cout << “This program can determine the temperature from Farenheit to Celcius.” << std::endl;
std::cout << “Please enter the temperature in ºFarenheit.” << std::endl;
std::cin >> fa;
cel=(int)5*(fa-32)/9;
std::cout << “The temperature given in ºCelcius is… “<<cel << std::endl;
if (cel>100) {
std::cout << “The water can boil at this temperature at typical conditions… Be careful!” << std::endl;
}
else{
std::cout << “The water does not boil at this temperature.” << std::endl;
}
return 0;
}

Captura de pantalla 2016-02-17 a las 18.30.35

#WSQ04-Flipped learning

I think that universities should give the flipped learning a chance, since I saw the video about The Differences between a Traditional and a Flipped Classroom, i found that there is a big difference between both of them, flipped classroom is more relax, also you have got more time to ask and share new information from the course that could be really useful to other classmate or oven the teacher, because he/she has to know if the students are really learning or have specific problems individually or as a group.

So just take a chance and try!!!

#AbolishGrades #TEC #IMD #SolvingProblemsAsEngineer #C++ #TC101