Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 19th, 2013, 08:56 AM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Script finalnote

Hi everyone
I need your help to write the following script.
thank you

Write a Perl script that calculates noteFinale.pl literal note of a group of students.
The data are provided to you in the file notes.csv. You must calculate the
results and record ceuxci
in the file note_finale.csv. Note literal is determined
by the total of all the ratings and according to the following table:
Note literal numeric score
90 <= 100 A
80 <= 89 B
70 <= 79 C
60 <= 69 D
0 <= 59 E
In addition, if a student gets literal note E, the reference should appear FAIL
in the result file. The output file will contain the following information:
• the name and surname of the student;
• the notes in the order TP1, TP2, INRA, Final, Total;
• Note literal final
• identification of failure if applicable.

Reply With Quote
  #2  
Old January 19th, 2013, 11:29 AM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,161 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 13 h 39 m 41 sec
Reputation Power: 1736
Think you forgot to add the script, can only see the description of your task (homework?).

Reply With Quote
  #3  
Old January 19th, 2013, 12:11 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
Yes, this looks like a homework and it seems to be fairly simple.

Please provide your attempt to do it by yourself and ask for help on any trouble you encounter. But don't ask for someone to do your assignment, that would really not help you in less short term, when you'll get a less simple one.

Reply With Quote
  #4  
Old January 19th, 2013, 12:16 PM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Hello
I'm a beginner programming in perl. I don't know write in other file. Here's what I've done.
thank you
***********
#! usr/bin/perl -w
use strict;
system "clear";
my @ligne;
my $note;
print "content type : fichier csv \n\n";
open (FILE, "notes-1.csv")|| die ("Erreur");
open (FIC, "> notes.csv")|| die ("Erreur");
while (<FILE>){
chomp;
@ligne = split(",",$_);
if ($. > 1){
$note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

}

}
print FIL ($ligne[2],$note );
close(FIC);
close(FILE);

Reply With Quote
  #5  
Old January 19th, 2013, 12:18 PM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Quote:
Originally Posted by nizar75
Hello
I'm a beginner programming in perl. I don't know write in other file. Here's what I've done.
thank you
***********
#! usr/bin/perl -w
use strict;
system "clear";
my @ligne;
my $note;
print "content type : fichier csv \n\n";
open (FILE, "notes-1.csv")|| die ("Erreur");
open (FIC, "> notes.csv")|| die ("Erreur");
while (<FILE>){
chomp;
@ligne = split(",",$_);
if ($. > 1){
$note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

}

}
print FIL ($ligne[2],$note );
close(FIC);
close(FILE);


the contents of the file fichier csv
Nom,Prenom,tp1,intra,tp2,final
Beethoven,Ludwig,25,22.25,20,23
Mahler,Gustav,20,19.5,18.75,18.75
Chopin,Frederick,14,15,17,12
Straus,Richard,22,18.75,19,21.25
Tchaikovsky,Pietor Ilitch,18.5,19.75,15,16

Reply With Quote
  #6  
Old January 19th, 2013, 01:02 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
Yeah, it is much better to provide your attempt, which is not too bad and should more or less work up to the point you've got, except that you want to print out your result for each student, i.e. within the reading loop, not after.

There seems to be an inconsistency between the assignment statement and your data: all marks seem to have a maximum value of 20 and you have only four of them. Even geniuses like Beethoven, Mahler of Chopin are unlikely to get an A or a B.

All you still have to do is to find the literal score, to check for failure and print your results for each student, before reading to the next line (i.e. within the loop).

The syntax to write to a file whose filehandle if FIC could be for example something like this:

perl Code:
Original - perl Code
  1. print FIC "@ligne ", $literal_mark, " ", $note, "\n";


Please tell if you have any other problem.

Reply With Quote
  #7  
Old January 19th, 2013, 05:03 PM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Thank you sir Laurent_R,
I can execute the code now, but I have a problem
I want priny in first line only the column names on the last line and the coma must separate columns.
#! usr/bin/perl -w
use strict;
system "clear";
my @ligne;
my $note =0;
my $mention;
my $lateral ="";
print "content type : fichier csv \n\n";
open (FILE, "notes-1.csv")|| die ("Erreur");
open (FIC, "> notes.csv")|| die ("Erreur");
while (<FILE>){
chomp;
@ligne = split(",",$_);
if ($. > 1){
$note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

}
if ($note >= 90 && $note <= 100){
$lateral = "A";
$mention = "";
}

elsif ( $note >= 80 && $note < 90 ) {
$lateral = "B";
$mention = "";
}

elsif ($note >= 70 && $note < 80) {
$lateral = "C";
$mention = "";
}

elsif ($note >= 60 && $note < 70) {
$lateral = "D";
$mention = "";
}

else {
$lateral = "E";
$mention = "echec";

}
print FIC "@ligne", "," , " ", $note, " ,", $lateral," ,", $mention ,"\n";
}



close(FIC);
close(FILE);

Reply With Quote
  #8  
Old January 19th, 2013, 05:57 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
If you want comma-separated values in your output, try to change:

Code:
print FIC "@ligne", "," , " ", $note, " ,", $lateral," ,", $mention ,"\n";

to

Code:
my $output_line = join ", ", @ligne, $note, $lateral, $mention;
print FIC $line, "\n";


If you want to print the column names on the first line of your output, then print the line when you are testing whether it is the first line of input. Something like this:

Perl Code:
Original - Perl Code
  1. while (<FILE>){
  2.     chomp;
  3.     if ($. == 1) {
  4.          print FIC $_, ", Total, Literal, Failed \n"; # prints input line + additional fields
  5.      }
  6.      else {
  7.           @ligne = split(",",$_);
  8.           $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];
  9.           # ...
  10.  


As a side note, it is today considered standard good practice to:

- use the "use warnings;" pragma, rather than "-w" flag on the shebang line
- use variable rather than bare words for file handler and use the 3 arguments syntax for opening a file, print the system error if any (the $! variable):

Perl Code:
Original - Perl Code
  1. open my $FILE, "<", "notes-1.csv" or die "Error opening notes-1.csv $! \n";
  2. open my $FIC, ">", "notes.csv" or die  Error opening notes.csv $! \n";
  3. while (<$FILE>){


If you do so, of course you have to change FILE to $FILE and FIC to $FIC wherever they appear. And by the way, I would use variable such as $IN_FILE and $OUT_FILE, rather than $FILE ans $FIC, as descriptive variables names help avoiding mistakes.

But, of course, if your instructor did not teach this way of opening files, you might prefer, for this assignment, to follow what you were shown to do.

Reply With Quote
  #9  
Old January 19th, 2013, 06:28 PM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Thank you very much, it's execute successfully, I have just a small bug, the code still display 0, E, echec at the first line (column name). I can't find the answer. You can help me.
sincerly

Reply With Quote
  #10  
Old January 20th, 2013, 05:14 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
Please provide the code that gives you this faulty output, as well as the exact output.

Reply With Quote
  #11  
Old January 20th, 2013, 06:12 AM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
Hi
You can give me your mail for send you my program.
Thank you

Reply With Quote
  #12  
Old January 20th, 2013, 11:09 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
Hi,

just post the relevant part of your program and the relevant lines of output here.

Reply With Quote
  #13  
Old January 20th, 2013, 11:55 AM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
first part

if ($. == 1) {
print $FIC $_, ", Total, Literal, Mention \n"; # prints input line + additional fields
}
else {
@ligne = split(",",$_);

$note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];
}

second part

my $output_line = join ", ", $note, $lateral, $mention;
print $FIC $output_line , "\n";

thank you for your help

Reply With Quote
  #14  
Old January 20th, 2013, 12:40 PM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 542 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 5 Days 2 h 16 m 32 sec
Reputation Power: 406
Please provide the output which you consider to be faulty. So far, I do not understand where your problem is (and what it is).

Reply With Quote
  #15  
Old January 20th, 2013, 12:56 PM
nizar75 nizar75 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 10 nizar75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 9 sec
Reputation Power: 0
at output I have
nom, prenom, tp1, intra, tp2, total, lateral, mention
0, E, echec
My bug is 0, E, echec, I don't want to displaying this line.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Script finalnote

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap