View Full Version : Anybody know C++?
thispego
07-30-2006, 02:10 PM
it'd be alot cooler if someone did :smokin
danyel
07-30-2006, 02:19 PM
I know a bit but Im no specialist, whats your problem?
thispego
07-30-2006, 02:26 PM
Write a program that reads records from an input file (prog5inp.txt). Each record contains a student ID#, the student’s semester average, and the student’s assigned letter grade. The program determines how many of each letter grade was assigned and writes in tabular form the input values plus the ‘calculated’ values to an output file, prog5out.txt. Do not use functions other than main to solve this problem. All code should be kept inline. Do not use classes or arrays.
I'm supposed to use a count loop
thispego
07-30-2006, 02:31 PM
general form
declare loop index variable
for (initialize loop index variable; test logical expression ; increment)
{
execute statement(s);
}
e.g.
#include <iostream>
int main()
{
int i;
for (i = 4; i >= 1; i = i - 1)
{
cout << "Hello" << endl;
}
return 0;
}
this is an example of a count loop, i'm just not sure how to plug it in to the program using what I need. C++ is so particular which makes it so complicated
danyel
07-30-2006, 02:33 PM
I'm not familiar with the term "count loop" if that has a meaning of its own, but it doesn't seem like a really hard program to do.
You read the input file, while the id doesnt changes for each record you add one to the according counter (one for each possible grade letter).
Once the Id changes you write the output record with the totals in the counters, and then you reset them to zero.
thispego
07-30-2006, 02:37 PM
I'm not familiar with the term "count loop" if that has a meaning of its own, but it doesn't seem like a really hard program to do.
You read the input file, while the id doesnt changes for each record you add one to the according counter (one for each possible grade letter).
Once the Id changes you write the output record with the totals in the counters, and then you reset them to zero.
so then(using previous example)~
#include <iostream>
int main()
{
int number_of_student;
for (number_of_student = 1; number_of_student >= 1; number_of_student = number_of_student + 1)
{
cout >> student_id >> student_smstr_avg >>
student_grade;
}
return 0;
}
??
thats totally wrong isnt it?
danyel
07-30-2006, 02:39 PM
In C, for acts as a while structure, so you could do something like this
int main()
{
openfile
for (file.movefirst; file.eof(); file.movenext)
{
count grades and write output
}
closefile
return 0;
}
Sorry, I dont remember C++ syntaxis
thispego
07-30-2006, 02:39 PM
I'm not familiar with the term "count loop" if that has a meaning of its own, but it doesn't seem like a really hard program to do.
You read the input file, while the id doesnt changes for each record you add one to the according counter (one for each possible grade letter).
Once the Id changes you write the output record with the totals in the counters, and then you reset them to zero.
how does it know when to stop?
danyel
07-30-2006, 02:45 PM
how does it know when to stop?
When the Id changes, you'd need to store in a variable the previous read Id.
thispego
07-30-2006, 02:47 PM
When the Id changes, you'd need to store in a variable the previous read Id.
thanks danyel, i'll try it out some more
katyon6th
07-30-2006, 02:51 PM
They taught us VB in school.
Fuck VB.
zero signal
07-30-2006, 02:56 PM
VB's kinda ok if you're into Windows.
I learned C/C++ because I had to for EE, but I wouldn't be caught dead programming something for myself in those languages. I like Ruby, Perl and Python best.
spurster
07-30-2006, 03:33 PM
Someone needs us to do this/her homework?
Can't you just copy most of what you need out of your textbook? You know, that thing made out of dead trees that you are supposed to read.
NorCal510
07-30-2006, 03:39 PM
Damn u got a c+ thats a good ass grade
thispego
07-30-2006, 05:12 PM
Someone needs us to do this/her homework?
Can't you just copy most of what you need out of your textbook? You know, that thing made out of dead trees that you are supposed to read.
no asshole
my dumbass teacher told us we probably wouldnt need the textbook
now i'm here wondering if I somehow got stuck into an upper level programming course where everyone seems to be 10 lessons ahead of me
zero signal
07-30-2006, 05:26 PM
That problem you were assigned is pretty simple. It's par for an introductory course.
But, as with any class in CS/SE/programming, it's normal to see people who are light years ahead of you.
thispego
07-30-2006, 05:31 PM
That problem you were assigned is pretty simple. It's par for an introductory course.
But, as with any class in CS/SE/programming, it's normal to see people who are light years ahead of you.
It would be very simple were it not for the conditions she placed on the program.
i think i'm one of two people in that class who are not CS majors :madrun
zero signal
07-30-2006, 05:40 PM
You don't need classes or arrays for this problem.
I agree that not being able to use functions is pretty fucking stupid, though. That just makes your program longer and harder for your teacher to read, and harder to debug.
Carie
07-30-2006, 05:40 PM
It would be very simple were it not for the conditions she placed on the program.
i think i'm one of two people in that class who are not CS majors :madrunThat is pretty basic logic for any programming class. But if most people in your class are way ahead of you, she may be adjusting how she teaches to their level. Sorry :(
Carie
07-30-2006, 05:42 PM
I agree that not being able to use functions is pretty fucking stupid, though. That just makes your program longer and harder for your teacher to read, and harder to debug.
I disagree. I think for a basic class, they are learning the logic behind the functions.
thispego
07-30-2006, 06:00 PM
That is pretty basic logic for any programming class. But if most people in your class are way ahead of you, she may be adjusting how she teaches to their level. Sorry :(
it's cool, ive pretty much come to terms with it, but what pisses me off is that she is making little to no effort to help me along.
3 summer classes = little time to devote to each outside of class
Das Texan
07-30-2006, 06:33 PM
I truly abhor C and C ++ programming languages.
zero signal
07-30-2006, 07:08 PM
I disagree. I think for a basic class, they are learning the logic behind the functions.
Well, that's true. Some students learn better with the sadistic approach :lol
LaMarcus Bryant
07-30-2006, 07:12 PM
no asshole
my dumbass teacher told us we probably wouldnt need the textbook
now i'm here wondering if I somehow got stuck into an upper level programming course where everyone seems to be 10 lessons ahead of me
Shrda, c++ was the language people are taught in high school, brah.
Man Sauce
07-30-2006, 07:49 PM
Do you go to Southwest Texas State?
thispego
07-30-2006, 08:05 PM
Do you go to Southwest Texas State?
yes i do
you had/have the class?
thispego
07-30-2006, 08:06 PM
Shrda, c++ was the language people are taught in high school, brah.
yeah, but back then it was c+p = copy + paste
PM or ask Baseline_Bum, he's a genius when it comes to programming/mathematics.
spurster
07-31-2006, 08:28 AM
no asshole
my dumbass teacher told us we probably wouldnt need the textbook
now i'm here wondering if I somehow got stuck into an upper level programming course where everyone seems to be 10 lessons ahead of me
Well, 90% of programming (at least, of the beginning sort) is copying what you need from a program that is close to what you want to do. Your textbook would/should have examples of reading in and printing out information. Maybe you have online notes that you can look at for this purpose.
Anyway, to give some help, you should first write a program that can open the input file, read the individual items from one line, print them out again, and close the input file. Then you'll need to put the read and print parts in a loop so they'll get done multiple times. Next, you will need to open and print to the output file. Finally, you'll need an if or a switch statement to count the grades, which you will print out after the loop. I assume because you are supposed to use a count loop that you can assume that there are a certain number of lines in the input file.
travis2
07-31-2006, 08:33 AM
I assume because you are supposed to use a count loop that you can assume that there are a certain number of lines in the input file.
Or use a "while not eof" condition...
SpursWoman
07-31-2006, 09:45 AM
no asshole
"asshole" is a college professor ... you might want to be a little nicer. :lol
tlongII
07-31-2006, 11:03 AM
That sounds like the same assignment I had 20 years ago! :lol
SpursWoman
07-31-2006, 11:04 AM
That sounds like the same assignment I had 20 years ago! :lol
Me, too ... writing in Pascal. :spin
baseline bum
07-31-2006, 05:24 PM
Why would you use a count loop for reading in input from a file? The only way it would work is if you knew exactly how many records you had to read in beforehand. Even if you did, it's just as easy to do something like...
while (is >> sid ) {
is >> avg;
is >> lgr;
/* do other stuff */
}
where is is the input stream you're reading from, sid is a std::string representing the student ID, lgr could be of an enumeration type with values {A,B,C,D,F}, and avg could be a float or an int, depending on how the grader stored it. There's no need to know how many records there are in this case, assuming each record is entered correctly in the prog5input.txt file. It's a much more flexible solution to just keep reading until you hit the end of the file, using the above code block.
mookie2001
07-31-2006, 08:47 PM
ShrdaROFL
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.