Hey World…
This may be my last post, because the semester has finished!!! Yeeey!!
So I will post a video on Youtube about the class review you can see it here.
Fundamentals and Solutions. Together!
Hey World…
This may be my last post, because the semester has finished!!! Yeeey!!
So I will post a video on Youtube about the class review you can see it here.
In this WSQ we need to create a program that asks the user for two pieces of data:
This is the WSQ where we need to create a program that ask for 10 numbers and it needs to store it in a list. The program need to show the total, the average and the standard deviation of those numbers.
For this program I used the math library to calculate the square root for the standard deviation.
Here is a picture of the code.
Here is the code running on cygwin.
Here is the link to the code in Github.
Python/WSQ-10 (Lists)
Here is my blog post for the WSQ 12.
Create a program that asks the user for a word which will be your search word and the name of a file to open and search for that word. Then create a function that will receive two parameters (both string) representing those two data points. This function returns the number of occurrences of that word in that file. Here is the link to my GitHub.
Here is the partial exam answered of course jajajaja so the exam just had four questions and I will list them in order.
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.
T TT TTT TTTT TTTTT TTTTTT TTTTTT TTTTT TTTT TTT TT T
//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);
}
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;
}
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
In this WSQ I used arrays of numbers to calculate via functions some mathematical operations given, for example to calculate the total, average and standard deviation of those numbers.
//CODE
#include <iostream>
#include <cmath>
using namespace std;
float total(float numbers[], int howMany){
float t = 0;
for (int num=0; num<howMany; num++){
t = t + numbers[num];
}
return t;
}
float average(float numbers[],int howMany){
float sum=0.0,prom=0.0;
for (int i=0; i<howMany;i++){
sum+=number[i];
}
prom=sum/howMany;
return prom;
}
float standarddeviation(float numbers[], int howMany){
float variation= 0.0, sum=0.0,prom=0.0,deviation=0.0;
for (int i=0;i<howMany;i++){
sum+=number[i];
}
prom=sum/total_num;
for(int i=0;i<howMany;i++){
variation=variation+pow((number[i]-prom),2);
}
deviation=sqrt(variation/howMany);
return deviation;
}
int main(int argc, char const *argv[]) {
float n, t, a, sd;
float num[10];
std::cout << “Enter 10 numbers Please.” << std::endl;
for (int i=0; i<10; i++){
std::cin >> n;
num[i]=n;
}
std::cout << ” Total,average,stdev of your numbers are..”;
t=total(num,10);
a=average(num,10);
sd=standarddeviation(num,10);
cout << t << std::endl;
cout << a << std::endl;
cout << sd << std::endl;
return 0;
}
Scilab es un paquete de código libre, que se basa en cálculos numéricos, se encarga de operaciones de matrices y en ámbitos científicos y de ingeniería, tiene cientos de funciones, tanto de propósito general,como especializado, ademas de contar con una excelente interfaz gráfica.
A través del comando “clc” podemos limpiar la consola ademas de contar con un historial de todos los comandos que hemos hecho.
Well kind of late but here are my codes from the partial exam, I will leave links for my codes in Github, hopefully you’ll find useful.
Fundamentals of Programming, First Partial Examination
Thursday, April 7, 2015
1. Escribe el función distancia cual recibe 4 números (x1, y1, x2, y2) cuales representan dos puntos en espacio (x1,y1) y (x2,y2). El método debe regresar la distancia entre los dos puntos. Recuerda que el valor cuadrada del hipotenusa del triangulo es igual que la suma de las cuadradas de los otro dos lados del triangulo (the hypotenuse squared is equal to the sum of the squares of the other two sides).
Aquí está mi código funcionando:
import math
def distancia (x1,y1,x2,y2):
resultado=math.sqrt((x2+x1)**2+(y2+y1)**2)
return resultado
fin=distancia(1,2,3,4)
print(fin)
Por aquí el enlace a Github.
2. Escribe un función que se llama triangulo cual recibe un parámetro size y imprime un triangulo derecho como el siguiente. El renglón mas grande debe llevar size numero de “T”. SOLO imprime los “T”s y los endlines. Nota que no hay characteres (espacios) a la derecha de los T’s. Debe usar un ciclo “for” para controlar el repetición. Ejemplo es si size era 6.
Aquí está mi código:
numero=int(input(“Por favor dame el tamaño de tu triangulo “))
def triangulo (var):
r=range(1,var)
r2=range(var,0,-1)
for x in r:
resultado=“T”*x
print(resultado)
for y in r2:
otra=“T”*y
print(otra)
triangulo(numero)
Por aquí el enlace a Github.
3. Escribe un función que se llama superpower(a,b) con dos parameters de (enteros / int). Debe regresar el valor del primer parametro al poder del segundo, o mejor decir a b . No puedes
Hello everyone! this WSQ is different, well kind of, what to d0:
Create a program that asks the user for 10 numbers. Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers. I found some very useful videos and tutorials:
Well finally this is the link for my code in GitHub.