#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this nine week class I started with doing this WSQ09. I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++.

Futhermore in this assignment we have two new mastery topics covered #Mastery19 Creation and use of strings and #Mastery21 Reading and writing of text files.

What I did for this numeric program is solving the problem to the user by writing a function that receives as parameter the name of a file (this would be a string value like data.txt) and this function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). I will want to look at how to create/define and return a struct value from a function and how to open and read text files line by line.

Hence, the resources I need it to solve this program are here:

ken bauer

How to convert string to char

C++ Tutorial for Beginners 43 – How to Read from a .txt file using C++

The following photograph shows the solution to this problem:

wsq9v1

wsq9v2wsq9v3wsq9v4

Picture of author

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial

charactes
Continue reading "#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp"

RZArector

--Originally published at prgrm.co

Alright WSQ07.

This one had me smacking my pencil against my head for a while. We needed to make a program that asks the user for values and then it gives back the sum, average and standard deviation, using vectors.

Ok, piece of cake! Yeah right, Ken came along and told me to do it with functions, at this point it got interesting.

This is the main() of the program, let’s check it out by parts:

nt main(){
int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}


cout << endl << "The sum of the values you have selected is: " << sum(values);
cout << endl << "The average of the values you have selected is: " << average(values);
cout << endl << "The standart deviaton of this set of number is: " << standart(values) << endl;

return 0;

}
  1. First important part: vector <float> values(n). As you can see here the vector is being declared then in between “< >” you determine the type variable and finally the name of the vector and how many numbers it will have.
  2. Then the number of values the user will provide the program with:
 int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}

As you can see here, the program ask the user for the values wanted and then a for loop will store this values in the vector <float> values (n); 

That was the easy part now let’s move on to the functions, the first one will add up all

Continue reading "RZArector"

Lists!

--Originally published at my programming blog

The assignment of last week was to ask the user for 10 values and then calculate the standard deviation with those values, then you needed to change your program so that the user could tell you how many values he wanted to enter.

It was easy to calculate the standard deviation when you ask the user for 10 values, but when I wanted the user to tell me the size of the array I had a lot of problems.

This is what I did:

  1. First I did my function and in the parameters I included the array and the integer size (which is the size the user will enter).
  2. Then I declared my values which were floats, sum=0, average, sum2=0 and SD
  3. Then I did a for loop where while i was less than the value of size there will be a sum of values.
  4. Then that sum that was calculated I divided it by the integer size to calculate the average.
  5. Then I did another for loop where when i was less than the size, then there will be a sum2 that will be equal to the sum of the  first value entered minus the average and that to the power of 2, (so you need to include the cmath library).
  6. Then I equaled SD to the sum2 divided bye the size of the array, and my function will return SD.
  7. In my int main I declared the integer size and I asked the user for the value of size.
  8. Then I declared my array with the value inside the brackets “size”. So that the program knows that the size of my array is equal to the size entered by the user.
  9. Then I asked the user for the values and I did a for loop where while i
    screen-shot-2017-03-06-at-10-39-48-am
    screen-shot-2017-03-06-at-10-40-01-am
    screen-shot-2017-03-06-at-10-40-58-am
    Continue reading "Lists!"

#WSQ07 Lists 03/03/17 and WSQ07.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this eight week class I started with doing the survey of mid semester where I gave ideas in order to improve this course and this and this WSQ07. I started reviewing in creating and calling functions in C++. #Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program and #Mastery18 Creation and use of Arrays/ Vectors in C++.

What I did for this numeric program is solving the problem to the user by writing 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.Futhermore, Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

The quantity of the value depends of the quantity of the type float variable that has only 32 bits of leght, therefore you need a new library in order to increase the value of numbers called Biginteger.hh but I am going to add it in the next WSQ08 called Yo soy 196. Next, to deal with an unknown size of my array during compilation we need to ask the user the number of that size and save it in a variable n.

The resources I need it to solve this program are here:

ken bauer

Similar code made by Eduardo Torres

C Programming Tutorial: Functions (Call By Value, Reference,passing Arrays to function)

The following photograph shows the solution to this problem:

wsq7v2

wsq7v3

wsq7v4wsq7v5

wsq7v6

Picture of author

So at first I wrote the same structure of the program just did the same as

s1
s2
s3
s4
s5
Continue reading "#WSQ07 Lists 03/03/17 and WSQ07.cpp"

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


Números, en lista, Ya!

--Originally published at Adal´s Blog



O era actividad ???


En el libro viene una sección donde explican lo básico pero necesario para saber que son los arreglos, con esa información y un apartado de la aplicación Aprende C++ pude hacer el ejercicio
 Paginas de ayuda: