I am having trouble formatting my output into columns. Some of the the names are longer than others so it pushes the whole line out instead of lining up evenly. I cannot use the printf function, we haven't learned this in class yet, I'm only familiar with setw and setfill. I'm also having trouble getting my output to copy to a text file. Half of the output is sent there but the other half with the actual output of the names, averages, and grades are not. Any help would be greatly appreciated!
please do not use this, system functions are bad and do not work the same way for different systems, for example, my comp(macOS) does not find a "pause" command and does not run the program.
second:
while(fin) does not work for me, so the content in the while loops is not actually done. if you want it to go until end of file do something like fin.eof() but i am not sure what you are trying to accomplish there.
cout<<"**************************************************"<<endl;
cout<<"* IT210 Business Applicatins with C++ *"<<endl;
cout<<"* Date: March 19, 2012 *"<<endl;
cout<<"* Program Assignment 3 *"<<endl;
cout<<"* Student Grades II *"<<endl;
cout<<"* *"<<endl;
cout<<"* This program reads student informantion *"<<endl;
cout<<"* from an input text file and ouputs results *"<<endl;
cout<<"* to the monitor and the ouput text file. *"<<endl;
cout<<"**************************************************"<<endl;
use
1 2 3 4 5 6 7 8 9 10
cout<<"**************************************************"<<endl
<<"* IT210 Business Applicatins with C++ *"<<endl
<<"* Date: March 19, 2012 *"<<endl
<<"* Program Assignment 3 *"<<endl
<<"* Student Grades II *"<<endl
<<"* *"<<endl
<<"* This program reads student informantion *"<<endl
<<"* from an input text file and ouputs results *"<<endl
<<"* to the monitor and the ouput text file. *"<<endl
<<"**************************************************"<<endl;
I know it doesn't help you with your actual problem but you did say ANY help would be greatly appreciated
I have to use the system functions because that's how I was taught and if not I'd probably get points taken off on my assignment. Where would I put the fin.eof() and what does exactly mean?
@Jadax Thank you, that would make my life much easier, specially when it comes to test time.
umm, does your teacher say "use system functions" because they are HUGE holes in your program that are OS specific. and .eof() is a boolean function that determines if the end of the file (eof) has been reached, and then returns a true value. so you would do while(!fin.eof()) // while not end of fin
No those aren't his exact words but regardless I am in a beginner course and I'm sure as I continue on to different classes I'll learn about these holes and different ways to accomplish the same thing. Thanks for explaining the .eof() I'll add it into my code.
.eof() is a boolean function that determines if the end of the file (eof) has been reached, and then returns a true value. so you would do while(!fin.eof()) // while not end of fin
You will hardly ever do this, because it is very rarely the right thing to do. It certainly isn't here. What he did in the control expression is the correct thing to do.
qsort ← {1≥⍴⍵:⍵⋄e←⍵[?⍴⍵]⋄ (∇(⍵<e)/⍵) , ((⍵=e)/⍵) , ∇(⍵>e)/⍵}
qsort 1 3 5 7 9 8 6 4 2
1 2 3 4 5 6 7 8 9
Of course, in real APL applications, one would use ⍋ to sort (which will pick a sorting algorithm suited to the argument).
- Sometimes I just want to say, that one should pick the right tools for a job.
In this example of a merge sort program the one line comment is longer than the program.
mKay, would you please post a copy of the input & output files; fin.open("input3.txt");
fout.open("input3_ouput.txt");
I see, and this may only be on my machine, that I have trouble with fin and fout with STRING vars. In particular, 'lastname' and 'firstname'.
fin & fout work on DOUBLES just fine.
mKay, since all of your averages are of fixed length ( nn.nn) then the spaces between those averages can also be fixed in size.
However because your names (firstname, lastname) are variable , then by starting your first average at a fixed distance from the end of the name, then the averages seem to move to the left, and cause the line, in full, to look jagged.
A solution for this is to determine, or set an arbitrary max size for the vars firstname & lastname , for example firstname(8), lastname (11)- since you currently only have 20-21 spaces before the "PROGRAM" header,
Create a variable for the space - rather than a fixed size of 12
For each name (first & last) - subtract that size (or length) from 21
and assign that value to the space-variable
for example: "Robert Johnsen" contains 14 chars
" Bob Able" contains 8 chars
In each case you want to begin the first AVG in position 22
so for Robert, subtract 14 from 22 and set the SpaceVar to 8.
In Bob's case subtract 8 from 22 and set the SpaceVar to 14.