Darkstar757
Diamond Member
Here the program specs
Write a Perl program to do the following:
1. Prompts for the complete path name, e.g. /home/shen/studentScores/class1, from the standard input (the terminal) of a file which is a text file. The first line in this file looks like the following:
Subjects- English Composition, Advanced Mathematics, Geography, History, Art
The first word must be Subjects and it is followed by a dash, as shown above. It is then followed by an arbitrary number of subject names separated by commas and possibly with arbitrary leading blanks in front of subject names. A subject name may have one or more words. In the above, five subject names were given.
After the first line, there are then an arbitrary number of lines of text such as the following three lines:
John Smith 77 82 49 79 95
Bill J. Bush, Jr. 87 89 93 40 80
Mary K. Bush 88 72 71 59 82
Each of the lines contains one or more words of a student's name. A student's name may not contain any digits but may have other characters as we know that may be in names. Following the student name, the numbers represent the scores the student obtained in subjects given in the first line, in that order.
2. Reads the complete path name which includes the file name and then picks up the file given in the pathname. It then reads that input file.
3. After reading the entire input file, for each subject, first prints on the standard output (the terminal) the subject title, then in each line a student name followed by the student's score in this subject. The students must be ordered in descending order of their scores in the subject. As an example, if the above sample input lines were the only ones in the file, then the program would print the following for the first two subjects:
English Composition
Mary K. Bush. 88
Bill J. Bush, Jr. 87
John Smith 77
Advanced Mathematics
Biil J. Bush, Jr. 89
John Smith 82
Mary K. Bush 72
My problem is I cant get the split function to work right.
I can get it to seperate the name but no each score of the student
here is my code
#!/usr/bin/perl -w
##print "Please Enter The Path Name of The Input File\n";
##print "Press Return Once You Have Entered The Path\n";
##chomp ($GRADES = <STDIN> );
open(GRADES, "hot.txt") or die "Can't open grades: $!\n";
while ($line = <GRADES>) {
#($student, $grade)=join('.',$line);
($student, $grade) = split(/([0123456789])/,$line);
$grades{$student} .= $grade ."";
print "$student\n";
print "$grade\n";
}
#/
#foreach $student (sort keys %grades) {
#$scores = 0;
#$total = 0;
#@grades = split(" ", $grades{$student});
#foreach $grade (@grades) {
#$total += $grade;
#$scores++;
#}
#$average = $total / $scores;
#print "$student: $grades{$student}\tAverage: $average\n";
#}
BTW this is not Home work and this is NOT FOR A GRADE.
I am doing this to further my programming skills which appear to be weaker than I thougt
🙁
Any help we be greatly appreciated
Thanks
Darkstar757
Write a Perl program to do the following:
1. Prompts for the complete path name, e.g. /home/shen/studentScores/class1, from the standard input (the terminal) of a file which is a text file. The first line in this file looks like the following:
Subjects- English Composition, Advanced Mathematics, Geography, History, Art
The first word must be Subjects and it is followed by a dash, as shown above. It is then followed by an arbitrary number of subject names separated by commas and possibly with arbitrary leading blanks in front of subject names. A subject name may have one or more words. In the above, five subject names were given.
After the first line, there are then an arbitrary number of lines of text such as the following three lines:
John Smith 77 82 49 79 95
Bill J. Bush, Jr. 87 89 93 40 80
Mary K. Bush 88 72 71 59 82
Each of the lines contains one or more words of a student's name. A student's name may not contain any digits but may have other characters as we know that may be in names. Following the student name, the numbers represent the scores the student obtained in subjects given in the first line, in that order.
2. Reads the complete path name which includes the file name and then picks up the file given in the pathname. It then reads that input file.
3. After reading the entire input file, for each subject, first prints on the standard output (the terminal) the subject title, then in each line a student name followed by the student's score in this subject. The students must be ordered in descending order of their scores in the subject. As an example, if the above sample input lines were the only ones in the file, then the program would print the following for the first two subjects:
English Composition
Mary K. Bush. 88
Bill J. Bush, Jr. 87
John Smith 77
Advanced Mathematics
Biil J. Bush, Jr. 89
John Smith 82
Mary K. Bush 72
My problem is I cant get the split function to work right.
I can get it to seperate the name but no each score of the student
here is my code
#!/usr/bin/perl -w
##print "Please Enter The Path Name of The Input File\n";
##print "Press Return Once You Have Entered The Path\n";
##chomp ($GRADES = <STDIN> );
open(GRADES, "hot.txt") or die "Can't open grades: $!\n";
while ($line = <GRADES>) {
#($student, $grade)=join('.',$line);
($student, $grade) = split(/([0123456789])/,$line);
$grades{$student} .= $grade ."";
print "$student\n";
print "$grade\n";
}
#/
#foreach $student (sort keys %grades) {
#$scores = 0;
#$total = 0;
#@grades = split(" ", $grades{$student});
#foreach $grade (@grades) {
#$total += $grade;
#$scores++;
#}
#$average = $total / $scores;
#print "$student: $grades{$student}\tAverage: $average\n";
#}
BTW this is not Home work and this is NOT FOR A GRADE.
I am doing this to further my programming skills which appear to be weaker than I thougt
🙁
Any help we be greatly appreciated
Thanks
Darkstar757