WSQ13

P2v2

q1_

Gráfico1.JPG

código:

#include<iostream>

int main()
{
using namespace std;
int num,i,x;
cout << “Dame el tamano del triangulo”<<endl;
cin>>num;
for(i=1;i<=num;i++)
{
for(x=1;x<i+1;x++)
{
cout<<“T”;
}
cout<<endl;
}
for(i=num;i>=1;i=i-1)
{
for(x=i;x>=1;x=x-1)
{
cout<<“T”;
}
cout<<endl;
}
return 0;
}

q2_

Gráfico1.JPG

código:

#include<iostream>
#include<math.h>
long superpower(long a,long b)
{
using namespace std;
long res;
res=pow(a,b);
cout << “El resultado de “<<a<<“^”<<b<<“=”<<res<<endl;
}
int main(){
using namespace std;
long base,exp;
cout << “Dame la base del numero a elevar”<<endl;
cin>>base;
cout << “Dame el exponente del numero a elevar”<<endl;
cin>>exp;
superpower(base,exp);
system(“pause”);
return 0;
}

q3

Gráfico1.JPG

#include<iostream>
#include<math.h>
#include<cstdlib>
long fibonacci (long n){
using namespace std;
long a=1,b=0,res,i;
if(n==2)
{
cout << “El resultado de nivel es 1″<<endl;
}
else
{
if(n==1)
{
cout << “El resultado de nivel es 0″<<endl;
}
else
{
for(i=1;i!=n-1;i++)
{
res=a+b;
b=a;
a=res;
}
cout << “El resultado de nivel es “<<res<<endl;
}
}
}
int main(){
using namespace std;
long num;
cout << “Cual es el nivel al llegar el fibonacci”<<endl;
cin>>num;
fibonacci(num);
system(“pause”);
return 0;
}

WSQ13: Exam corrections

#TC1017 #WSQ13

Q1:

For this first question we had to print out a kind of rotated pyramid, which I must say I found somewhat complicated because of the nested ifs. All important notes can be found in the source code:

Captura

 


 

Q2:

The superpower one. We had already done this as a quiz, but I didn´t realize my old code wasn´t really working so it took me a while to realize what I was doing wrong. It turned out I had to multiply the result by the base, and I was doing some weird additions. But now it works perfectely.

Captura.PNG


 

Q3:

The fibonacci series was also already done before, it is quite simple.

Captura.PNG


Q4:

This last problem I could not complete, but here is my source code:

#include <iostream>
#include <string>

using namespace std;

int FindPali(string word){
int i, j;
int size = word.size();

/*This cycle should compare all indices to their opposites to chech for symmetry and decide wheter it is a palindrome or not, however it is not doing anything it seems.*/
for (i=0; i<size; i++){
} cout << word[i];
for (j=size; j>0; j–){
} cout << word[j];
if (word[i] == word[j]){
return 1;
}

}

int main(){
string word;
cout << “Please enter the word:” << endl;
getline (cin, word);

if (FindPali(word)==1){
cout << “Palindrome!” << endl;
} else {
cout << “Not a palindrome.”<< endl;
}

}

GitHub link including all questions: https://github.com/diegodamy/Exam2-Q1

WSQ13 – Exam 2nd Partial

istock_000014033663medium

El propósito de este post, es publicar los enlaces de los códigos realizados en el examen del segundo parcial de esta materia.

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

Link GitHub: Exam 2 – Prog 1

Programa 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 a b So, superpower(3,4) would return 81. long superpower(long a, long b){

}

Link GitHub: Exam 2 – Prog 2

Programa 3

NOTE: for full 5 points, use a loop (not recursion). 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 1. All others are the sum of the previous two fibonacci numbers.

Link GitHub: Exam 2 – Prog 3

Programa 4

Write a function called isPalindrome which receives a string “x” and returns true if the string x is a palindrome, otherwise false.

Link GitHub: Exam 2 – Prog 4

WSQ13 Exam review

On this post I’ll show the correct code for the problems of the second partial exam.

During the exam, I was able to solve just a few of the problems asked, however, on this post are the problems solved.

It was good to make this activity, in order to learn from our mistakes.

Click on each of the links to see the solution on GitHub:

 

Problem 1

Problem 2

Problem 3

Problem 4

Greetings!!

 

WSQ13- Correciones

Estas son las correcciones de mi segundo parcial:

El primero ejercicio fue el de sacar la distancia entre dos puntos, lo cual lo que me fallo fue entender la formula, después de a ver la investigado logre hacer el ejercicio:

import math

puntox1= int(input("Posicion de la cordenada X1: "))
puntoy1= int(input("Posicion de la cordenada Y1: "))
puntox2= int(input("Posicion de la cordenada X2: "))
puntoy2= int(input("Posicion de la cordenada Y2: "))

def distancia (x1,y1,x2,y2):
lejitos=math.sqrt((x2-x1)**2+(y2-y1)**2)
return lejitos

print("La distancia entre el punto (",puntox1,",",puntoy1,") y el punto (",puntox2,",",puntoy2,") es:","%.2f"%distancia(puntoy1,puntoy1,puntox2,puntoy2))

Este es el compilado:

Click en la imagen para código:

El segundo ejercicio que corregí fue el de potencia, el problema que tuve en este ejercicio fue encontrar la manera de que se acomulara cada vez que se elevara por si mismo, pero despues de muchas pruebas y errores lo consegui

def superpower (base,elevado):
aco=1
num=base
while(aco<elevado):
num=num*base
aco=aco+1
return num
base= int(input("Dame el numero base: "))
elevado= int(input("Dame la pontencia a la que se elevara:"))

print("La potencia del numero: ",base, "elevado a la: ",elevado," veces es: ",superpower(base,elevado))

Compilado:

Click en la imagen para ir a github:

EXAM 2

In this WSQ we correct the second parcial.

First part:

In this program you have to form a triangle with “T”

WSQ13-1+

Second part:

In this part you have to make a function to recive two numbers and solve a pow formula.

WSQ13-2

Third part:

In this part you have to make a program whit fibonacci formula and ask to the user for the number of terms.

WSQ13-3

#WSQ13, Partial 2 Exam

exam.jpg

Hello people! I’m back to post about the WSQ13, wich is about our Partial Exam. We made a practical programming exam that contained four programs to solve and in this WSQ we had to answer the programs correctly. So, here my solutions for them:

The first one was about the Fibonacci Numbers (we saw how to make it before), so I don’t have problem to make it. Here the screenshots of the program:

fibow

fibg

The second one consisted in make a program which calculates the operation a^b. As the first program, we made it before. Here, the screenshots:

spopppspppppo

In the third program, we have to make one program which make a Triangle asking to the user for the number of letters that he wants to conform the triangle. For example, if the user puts a 3, the triangles looks like –> t
tt
ttt
tt
t

And to get it, I used a for loop to add one T when it was lower than the number of the user, and to subtract one T if it was bigger than the user’s number.
The screenshots:

triantria

And finally the last program was about something that we made in the WSQ 11, Yo soy 196, but now we had to use Bools. I found it difficult because I’ve never used Bools but as we all known, internet is God and I found a lot of information about it, here some links to be smarter: (http://www.zator.com/Cpp/E3_2_1b.htm) & (http://www.cplusplus.com/forum/beginner/124090/)

**I had to thank to my friend Sergio Zavaleta who helped me making the program useful using lowercase and capital letters.

Here the screenshots:

boolpalt

And don’t forget to check my codes on GitHub.

1st Program: https://github.com/eduardomrlsg/TC101/blob/master/FiboEx

2nd Program: https://github.com/eduardomrlsg/TC101/blob/master/SPPEx

3rd Program: https://github.com/eduardomrlsg/TC101/blob/master/Trianglex

4th Program: https://github.com/eduardomrlsg/TC101/blob/master/PalEx

 

Regards. EdMo.