QUIZ 7

El último quiz! porfiinnn! el semestre está por terminar, en este quiz se tiene que calcular el producto escalar de dos vectores utilizando matrices (nuevo)

//CODE

#include <iostream>
using namespace std;

double dot_product(double list1[], double list2[], int l1){
double dot=0;
for(int i=0; i<l1; i=i+1){
dot=dot+(list1[i]*list2[i]);
}
return dot;
}

int main(){
int l1;
double product;

cout<<“This program help to calculate the dot product of the lists of values given by the user.”<<endl;
cout<<“Please enter the values to the first list.”<<endl;
cout<<“How many caracters the lists have?”<<endl;
cin>>l1;
double list1[l1], list2[l1];

for(int i=0; i<l1; i=i+1){
cout<<“Type the ” <<i+1<<” “<<“value of the 1st list.”<<” “;
cin>>list1[i]; }
cout<<“Please enter the values to the second list.”<<endl;

for(int i=0; i<l1; i=i+1){
cout<<“Type the ” <<i+1<<” “<<“value of the 2nd list”<<” “;
cin>>list2[i]; }

product=dot_product(list1, list2, l1);
cout<<“The dot product of both lists is:”<<” “<<product<<endl;
return 0;
}

Captura de pantalla 2016-05-14 a las 11.21.29.png

QUIZ 6

Este programa escribe una función para calcular el máximo común denominador de dos números positivos;

//CODE:

#include <iostream>
using namespace std;

int gcd(int x, int y){
int r;
if (x==0){
return x;
}
while (y!=0){
r= y;
y= x%y;
x= r;
}
return r;
}

int main (){
int x,y;
cout<<“Please enter a number: ” <<endl;
cin>>x;
cout<<“Please enter a second number: ” <<endl;
cin>>y;
cout<<“The greatest common denominator between (” <<x <<” y ” <<y <<“) is = ” << gcd(x,y) <<endl;

return 0;
}

Captura de pantalla 2016-05-14 a las 11.19.21.png

QUIZ 5

Este programa determina si la palabra dado por el usuario es un palíndromo o no con una simple condición, el programa la comprara de atrás hacia adelante y da el resultado:

 

//CODE:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

string word, fin;

string is_palindrome(string word)

{
string backwards;
cout << “Type a word: n”;
cin >> word;

int large = word.length();
for (int x = large – 1; x >= 0; x–)
{
backwards += word[x];
}
if (backwards == word)
{

fin = “Your word IS a palindrome”;
}
else
fin = “Your word IS NOT a palindrome”;
return fin;
}

int main()
{
cout << is_palindrome(fin);
}

Captura de pantalla 2016-05-14 a las 11.17.25.png

QUIZ 4

EN el quiz 4 el programa crea una función llamada euler_calc , el valor de precisión se utiliza para determinar cuándo parar el cálculo . El cálculo se detendrá cuando los dos valores consecutivos de estimación e difieren en menos de precisión

//CODE

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

double factorial(int n){
double fact = 1;
for (int i = 1; i <= n; i++){
if (n==0){
return 1;
}
else {
fact = fact * i;
}
}
return fact;
}
float euler_calc (float ac){
float e = 1.0;
for (int i=1; i<999; i++){
e = e + 1/(factorial(i));
}
cout<< fixed <<setprecision(ac) << e;
return e;

}
int main(){
float ac;
cout<<“How accurate you want the result? “;
cin>>ac;
cout<<“Here is your number: “<<endl;
euler_calc(ac);
cout<<endl;
return 0;
}

Captura de pantalla 2016-05-14 a las 11.12.26

QUIZ 3

El quiz 3 primero se relaciona con el plano cartesiano , y algunos puntos, el programa puede calcular la distancia entre los dos puntos , son dados por el usuario al azar , usando el teorema de la Pitágora solucionarla.

//CODE:

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

/*int x1, x2, y, y2;

void Distance(int x1, int x2, int y, int y2) {
int dx, dy, dist, C;
dx=(x2-x1);
dy=(y2-y);
C=((dx*dx)+(dy*dy));
dist=sqrt(C);
std::cout << “dx–“<<dx << std::endl;
std::cout << “dy–“<<dy << std::endl;
std::cout << “The distance between the points is… “<<dist << std::endl;
}*/

int main(int argc, char const *argv[]) {
int dx, dy, x1, x2, y, y2, dist, C;

std::cout << “This program calculates the distance between two points in the cartesian plane.” << std::endl;

std::cout << “Next enter the coordenates of the first point” << std::endl;
std::cout << “Please enter x1)” << std::endl;
std::cin >> x1;
std::cout << “Pease enter y1” << std::endl;
std::cin >> y;
std::cout << “Please enter x2” << std::endl;
std::cin >> x2;
std::cout << “Please enter y2” << std::endl;
std::cin >> y2;

dx=(x2-x1);
dy=(y2-y);
C=(pow(dx,2)+pow(dy,2));
dist=sqrt(C);
std::cout << “The distance between the points is… “<<dist << std::endl;
//Distance();
return 0;
}

Captura de pantalla 2016-05-14 a las 11.10.52.png

 

QUIZ 2

El segundo quiz fue separado en solo dos programas, el primero pregunta dos números diferentes al usuario y calcula con funciones el primero numero con el segundo

//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-05-14 a las 11.07.07.png

Este código es capaz de imprimir un cierto número de estrellas con un valor dado por el usuario . El uso de una función llamada “estrellas” y un bucle .

#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;
}

 

QUIZ 1

El quiz 1 fue dividido en tres programas, el primero se utiliza para calcular el volumen de un cilindro, el segundo calcula algunas operaciones básicas, y el tercero y ultimo es similar al segundo solo que en este las funciones son un poco más complejas aquí dejó mis instrucciones y código de cada uno:

//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;
}

 

//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;
}

//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

Continue reading “QUIZ 1”

WSQ13- 2 Parcial

Aquí esta resuleto correctamente el examen de segundo parcial, y con las instrucciones de como realizarlo:

QUESTION 1:

Write a function called triangles which receives a single parameter (int) which represents the size of a triangle as explained below. The function should print a triangle using loops (for or while). The only characters printed here are ‘T’ and the new-line character. The first line is length one, the middle line is length size and the last line is length one. The example below is for size 6.

//CODE

// Ever Olivares
#include <stdio.h>
#include <iostream>
using namespace std;

int triangle (int x)
{
for (int i=1; i<=x ;i++)
{
for (int j=1; j<i+1; j++)
cout <<“T”; cout <<endl;
}
for (int i=x-1; i>=1; i–)
{
for (int j=1; j<i+1; j++)
cout <<“T”; cout <<endl;
}
return 0;
}
int main ()
{
int y;
std::cout<<“type the numbers of T you want” <<std::endl;
std::cin >> y;
triangle (y);
}

Captura de pantalla 2016-05-14 a las 10.51.57.png

 

QUESTION 2:

Write a function called superpower that has two parameters of type long and returns a long which is first parameter raised to the power of the second, which is to say it returns ab So, superpower(3,4) would return 81.

//CODE:

// Ever Oliavres
#include <iostream>
#include <cmath>

void superpower(int num1, int num2){
int R;
R= pow(3,4);
std::cout << “The result is… “<<R << std::endl;
}

int main(int argc, char const *argv[]) {
int R;
superpower(3,4);

return 0;
}

Captura de pantalla 2016-05-14 a las 10.52.42.png

QUESTION 3:

Write a function called fibonacci which receives a long “n” and returns a long which is the value of the nth number in the fibonacci series which is: 0,1,1,2,3,5,8,13,21,34,55,89…………So, fibonacci(0) would return 0. fibonacci(5) would return 5, fibonacci(8) would return 21.Note that the first two fibonacci numbers are 0 and All others are the sum of the

Captura de pantalla 2016-05-14 a las 10.53.33.png
Captura de pantalla 2016-05-14 a las 10.54.22.png

Continue reading “WSQ13- 2 Parcial”