--Originally published at RAMGGV
Para este programa se nos pidió crear una función que reciba un parámetro y con este contar numero de lineas y caracteres.
--Originally published at RAMGGV
Para este programa se nos pidió crear una función que reciba un parámetro y con este contar numero de lineas y caracteres.
--Originally published at Hensel
Hola, en el wsq09 debíamos realizar una función, la cual recibiría como dato de entrada un texto dentro de un archivo y realizaría el conteo de cada carácter dentro del texto y el número de líneas. Dejo las imagenes de mi código con la explicacíon de cada paso en ellas.
--Originally published at Loading…
Hi!! Is almost the ending of this semester and I promised not to leave everything to the last minute… but here I am… doing all in the last minute.
Today I’m going to explain how I did the #WSQ09. To make this program I asked for help to my friend Jenifer Romero, she explained me everything, but the problem was that we did it on her Mac, so… I had to make some arrangements in order for it to work in my Windows computer.
This is what we had to do:
So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your 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). You 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
The first thing I did was to add the two necessary libraries <fstream> & <string>. Then, for make the “it returns as a single value (but with two values)” part, I added a struct that I called datos, which stores two int, l (for lines) and c (for the characters). Next, in my function (func) which receives the string url (or ruta) and called the struct. After that I wrote ifstream archivo(ruta.c_str(), ios::in) it associates it with the file name and opens it. I established my variables (at the final I don’t use the char car, ‘cause Ken helped me to do the same with less), and wrote a while for do the things until the
Continue reading "Multipart Data & Files" --Originally published at Programming course
So this is what Ken told us to do:
So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your 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). You 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
This is my code
And this is the help I used from a guy on Youtube:
--Originally published at Solving problems with programming
In this homework what we do is read a .txt file and count how many lines does it has and the total sum of characters. We use structures to just return a structure with the number of lines and characters. A structure is a variable that has many variables inside. To solve this homewor I got help from the blog of Fabrizzio and a tutorial that explains how to read an write on other files from c++.
#include <iostream> #include <string> #include <fstream> //Esta librería es la que permite que puedas leer otros archivos using namespace std; struct lector { //estructura de struct y variables dentro de lector int contlineas; int caracteres; int acumulador; }; lector lectordoc(string nombre){ lector contador={0,0,0}; string linea; ifstream file(nombre); //Esta función te permite abrir otro archivo ifstream, escribir es con ofstream. file(nombre) File es el nombre que le asignas al archivo abierto y nombre es la variable del nombre del archivo. if(file.is_open()){ while(getline(file,linea)){ contador.caracteres= linea.length(); contador.acumulador= contador.acumulador + contador.caracteres; contador.contlineas ++; } return contador; }else{ cout<<"No se pudo abrir el archivo intentalo de nuevo"<<endl; } } main(){ string archivo; lector informacion; cout<<"Escribe el nombre del archivo"<<endl; cin>>archivo; informacion=lectordoc(archivo); cout<<"El archivo tiene "<<informacion.contlineas<<" lineas y "<<informacion.acumulador<< " caracteres"<<endl; return 0; }
With this homework we cover #Mastery09. Here is the complete code if you want to download.
--Originally published at Programming Path
The assignment of #WSQ09 was the next one:
So for this assignment I would like to see you create a function that receives as parameter the name of a file (this would be a string value like data.txt) and your 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). You 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
This for sure was a new topic. It was thanks to Ken’s Disciple 01‘s blog that I could understand this task.
First I needed to make a text file (.txt) so I wrote a Skyrim quote. It is from an ancient dragon and I got attached to him because it was the only friendly dragon, but anyway here is the text:
Then we had to make the program open the file and count how many characters and lines does it has. Then print it out.
Thanks for reading.
--Originally published at estefilangarica.wordpress.com
The assignment Ken gave us was the following:
In this assignment you will write a function to calculate the square root of a number using the Babylonian method.
The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.
--Originally published at OlafGC / Class #TC1017
Hi guys! I just finished the video for WSQ09, the link and the code are bellow. A brief explanation: this WSQ is about Multipart data and Files. This program opens a text file and tells you the number of characters and files in it. Enjoy and thanks in advance for watching.
And the code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct charlines
{
int chars, lines;
};
charlines countCharLines(charlines & num)
{
string line;
num.lines=0;
num.chars=0;
ifstream file(“data.txt”);
if(file.is_open())
{
while(getline(file, line))
{
num.lines ++;
num.chars += line.size();
}
file.close();
}
return num;
}
int main()
{
charlines number;
countCharLines(number);
cout<<“File chars: “<<number.chars<<endl;
cout<<“File lines: “<<number.lines<<endl;
return 0;
}
--Originally published at TC1017 Programing Curse
This homework ask me to create a program that prints something that is in a .txt, it was a little difficult to understand how to do it but at the end after investigate it was actually easy
and also here we can see Mastery Topic 19, and 21
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string game, name;
cout<<“Tell me which game do you want to know its history “<<endl;
cout<< “(FallOut, Borderlands, Doom)”<<endl;
cin>>name;
if (name==”FallOut”){
ifstream file(“FallOut.txt”);
if(file.is_open())
{
while(getline(file,game))
cout<<game<<endl;
}
file.close();
}
else
{
cout<<“Try Later “<<endl;
}
}
else{
if(name==”Borderlands”){
ifstream file(“Borderlands.txt”);
if(file.is_open())
{
while(getline(file,game))
{
cout<<game<<endl;
}
file.close();
}
else
{
cout<<“Try Later”<<endl;
}
}
else{
if(name==”Doom”){
ifstream file(“Doom.txt”);
if(file.is_open())
{
while(getline(file,game))
{
cout<<game<<endl;
}
file.close();
}
else
{
cout<<“Try Later”<<endl;
}
}
}
}
return 0;
}
i just have to convert this into a fucntion.
image taken from: http://kotaku.com/lets-rank-the-fallout-games-best-to-worst-611408965
--Originally published at Ken's Disciple 01
It seems complicated, but it’s not.
Hi guys welcome to WSQ09 I’m going to show you how I found the way of doing this. Pretty much everything you need are functions that are already done with libraries, so It’ll be very easy once you try it. I’m going to give some links of things that helped me:
I’ll only change the name of my variables so you can compare with the pictures of my code: