I need to write a program square that calculates the squares of all numbers that are contained in a file of floating point numbers. The obtained new numbers form a new file. For example if the file contains the numbers 1, 2.5, 0.1, the numbers 1, 6.25 and 0.01 form the resulting file. The file names are specified on the command line:
This is a very simple program that should give you a little practice with reading and writing simple text files. You need to use ifstream for input file, and ofstream for output file. Then in a loop, read a number, square it, then write it out to the output file. That loop is only three statements long (while, square, write) If it takes you more than three statements then you are probably not coding it correctly. Actually, now that I think about it you could do it in fewer than 3 statements, but that may be pressing it a bit for you right now.
Yes, those are the two statements I had in mind. Some new programmers might find the logic easier to follow if they calculate number^2 in a separate statement.
If you want to redirect input from a file you can also use cout and redirect output to a file when the program is run from the command line, script or batch file (depending on the operating system). In that case you don't have to know a thing about ifstream or ofstream.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...