List…

--Originally published at Loading…

Activity:

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

This one was a little difficult because I didn’t know NOTHING about arrays or vectors in C++, that’s the reason why I didn’t submit nothing in the las 2 weeks. No matter how much I read or investigate in the book or internet, I didn’t understand how it works, until I found this classmate’s post and it was like the illumination for me. So, this is my code:

list

First I added the library <cmath> for the program recognize the operations. Then in my int main, I established my variables as float, and to make the list I used an array, for this you put a name, in my case “list”, then add the [ ] and in the middle you establish how many numbers you want to store, in this activity we want to store 10. The rest is ‘easy’ you just need to be careful in the operations, pow is a function of exponents and for the rest I think it doesn’t needs much explanation, anyway if you have any question you can leave a comment and I’ ll answer you. I hope I was able to help you.

This is how it works:

list02


Quiz 6

--Originally published at Loading…

I decided to make Quiz 6 before the Activity 7, because it seemed to me would be simpler, also the quiz is for this week. BUT this quiz was too different that the others, it was more time-consuming  and really tested me.

We had to do the first 5 exercises of this page, and they were a little bit different from what normally we do. I did them in disorder, but here they all are.

Activity 1, run a program.

This one was one of the most difficult, and not precisely because it was too hardcore, more like, it wasn’t running correctly through the fault of a parenthesis in the wrong place.

So, the activity was:

Type in the following program and run it:

#include 
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
	char c;  
	short s;  
	int i;  
	unsigned int ui;  
	unsigned long int ul; 
	float f;
	double d;  
	long double ld;  
	cout << endl 
  	     << "The storage space for each variable type is:"
	     << endl;
	cout << endl << "char: \t\t\t%d bits",sizeof(c)*8;  //  \t means tab 
	cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
	cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
	cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
	cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
	cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
	cout << endl << "double: \t\t%d bits",sizeof(d)*8;
	cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;

First I completed what it was needing to the program, added the libraries & , wrote using namespace std; (as always), and wrote int before the main. Then I substituted the cout << endl << for printf(. Later, in order to make sizeof( )*8 works Ken said that we need to wrote int( before. And that’s all, this is my code:

quiz6-1

With this activity I learned to use \t for add

quiz6-2
quiz6-3
quiz6-4
quiz6-5
whatsapp-image-2017-02-14-at-10-54-35-pm
whatsapp-image-2017-02-14-at-10-57-10-pm
Continue reading "Quiz 6"

Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics"

Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics"

Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that in my last post i learn all transversal topics that are:

  • Ability to create C++ file and run from command line (terminal)
  • Create accounts: Blog, Twitter, GitHub
  • Submit work via Blog RSS and GitHub
  • Demonstrate use of Linux sufficient for quizzes/exams
  • Install Linux on their own computer

And you can find it in these posts:

Post of the week #2 what things i learned in this week #2 ?

Post of the week #1 what things i learned in this week #1 ?

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of
    Continue reading "Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics"

Pick a Number

--Originally published at Tec Life

This was the problem:

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

There are different ways to make that happen, you choose which one works best for you.

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

I start adding the libraries that I search on internet “stdlib.h” and “time.h” to make the program to generate one random number, then I declare my variables as local variables because there are going to change and I start coding the thing that I need to make the program give me a random number, that says that is going to generate one random number between 1 and 100.

Then I make a loop in case if I don’t guess the random number that the program makes, and I put if the number I put randomly in order to guess the other number was less that it was the program is going to say me that the number insert was to low, and one in case it would be to high.

And if I guess it the program is going to say me congratulations :).

captura-de-pantalla-2017-01-23-a-las-09-31-34

#WSQ03


I have a number chosen between 1 and 100.

--Originally published at Loading…

The activity was:

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

So the first step was to remember how to generate random numbers, and as always I searched it in St.Google, and I found a very good page that helped my a lot. I add the <ctime> and <cstdlib> libraries to make the program works. Then I established my 2 variables with int, I wrote srand(time(NULL)), for make the number always random, and the equation.

To make that the program continue until the user guesses I add a do/while function, that includes an if function to set the parameters and give the hints of ‘too high’, ‘too low’ or BRAVO, if you guess. Before to making something more pro, I wanted to be sure that it works correctly, I compiled and guess what… It didn’t do it, you will never guess the number, i don’t know why but it change it every time, so I looked for help and I found it in a classmate’s blog, he has a char command with a condition, so I try it in my program and it works, so that was the solution. At the final I add an extra variable to count the opportunities, and an if to show if your a loser or a winner. This is my code at the final:

randrand02


I finished the quiz in time!!

--Originally published at Programming Path

Well, maybe I took me more time because of writing the post, but!!! I did it! I’m proud of myself!

We had to do a program with two specific functions:

  • double square_root(double x) {} ; // returns the square root of x
  • double cube_root(double x) {} ; // returns the cube root of x

The program needs to ask what number do you want to be x and the program will respond with it’s square root and it’s cube root.

For this, we have to add a function to the program and that was the challenge, at least for me, because I didn’t knew how does a function works and even less how to add it to the code. That is why I ask for help to my classmate Sergio. He was very helpful, thank you Sergio!!

This is what I did:

quiz3

and here is outside the photo:

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

double square_root (double);
double cube_root (double);
int main () {
double x, s, c;
cout << “I will give you the square and cube root of x. What is x? “;
cin >> x;
s = square_root (x);
c = cube_root (x);
cout << “Square root: ” << s << endl;
cout << “Cube root: ” << c;
return 0;
}
double square_root (double x) {
return sqrt (x);
}
double cube_root (double x) {
return cbrt (x);
}

So, the first thing I always do is insert the <iostream> and the namspace std. This time I added the library of the math functions which is <cmath>, because we will need it to solve the square and cube roots. I also add the values of them: double square_root (double);
double cube_root (double). What I understood was that we need to add this so

Continue reading "I finished the quiz in time!!"

Quiz #3

--Originally published at my programming blog

Today I did the Quiz #3, at first I was lost I didn’t understand very well how to make a function, but I asked for help and my classmates and my teacher helped me.

Once you understand it it’s not that hard.

What I needed to do was ask the user for a number and the calculate the square and cube root of that number, also I needed to include what happens if the user enters a negative number.

First I included the library cmath so I could use math functions in my program, after that I created my two functions, one for the square root and the other for the cube root and I specified what the function needed to do. And then started with the ” int main ()” and all my basic program and at the end I added an “if” to give the option of when the user entered a negative number.

So this is my code:

screen-shot-2017-01-26-at-10-15-19-am

#include
#include
using namespace std;

double square_root(double x){
return pow (x, 0.5);
}
double cube_root(double x){
return pow (x, 0.333);
}

int main(){
double x;
cout<<“Let’s find the square and cube root of a number!”<<endl;
cout<< “Give me a number:”<<endl; cin>>x;
if (x<0){
cout<<“Error! The number you entered is negative.”<<endl;
} else {
cout<< “The square root is: “<<square_root(x)<<endl;
cout<< “The cube root is: “<<cube_root(x)<<endl;
return 0;
}
}

And this is the program when I run it:

screen-shot-2017-01-26-at-10-20-35-amscreen-shot-2017-01-26-at-10-19-59-am


Cuanta suerte tienes?

--Originally published at Adal´s Blog


Quieres probar tu surte con un divertido juego?


Para poder hacer este código me enfrente a un pequeño detalle, el hecho de que no sabia como generar números al azar, pero gracias a aprenderaprogramar.com, me dieron una ayudita de como hacerlo, se los dejo aquí ▼:



Pagina de ayuda: