GIDForums  

Go Back   GIDForums > Computer Programming Forums > Miscellaneous Programming Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Aug-2007, 21:05
Reny's Avatar
Reny Reny is offline
Junior Member
 
Join Date: Aug 2006
Posts: 58
Reny is on a distinguished road

PERL: Problem with Read from file


I complete an exercise about input,calculate and output student GPA and CGPA to file.

Now my problem is the proceeded exercise wants me to record more than 1 student's GPA and calculate the CGPA from file. Need student to login using their ID. no only, check, change and add their GPA according to which semester.

My current read and output to file can't helps me to proceed the certain exercises.

So i need some helps here.

Here's my previous program.
CPP / C++ / C Code:
# calculate the GPA for student.
while()
{

	print("\n********************************************************\n");
	print("* NO.                     Content                      *\n");
	print("********************************************************\n");
	print("*  1                 Calculate GPA/CGPA                *\n");
	print("*  2                 View GPA/CGPA                     *\n");
	print("*  3                 Quit                              *\n");
	print("********************************************************\n");

	print("Enter the number : ");
	chomp($n =<STDIN>);

	if($n == 1)
	{
           print("Enter student's ID : ");
	        chomp($ID =<STDIN>);

      		print(" \nEnter the total number of semester to calculate : ");
      		chomp($s =<STDIN>);

      		for($count=1 ; $count <=$s ; $count++)
       		{
       		print ("\n\nPlease key in your semester $count subject information and press 0 to stop");
      		print ("\n\nPlease key in your subject grade:");
       		$grade = <STDIN>;
       		chomp($grade);

       		while($grade ne 0)
                {
       		     print ("\nPlease key in the subject unit:");
       		     $unit = <STDIN>;
       		     chomp($unit);

  	              if (($grade eq "A")||($grade eq "a"))
                         {$g = 4.00;}
	              elsif (($grade eq "A-")||($grade eq "a-"))
                         {$g = 3.67;}
	              elsif(($grade eq "B+")||($grade eq "b+"))
                         {$g = 3.33;}
	              elsif(($grade eq "B")||($grade eq "b"))
                         {$g = 3.00;}
	              elsif(($grade eq "B-")||($grade eq "b-"))
                         {$g = 2.67; }
	              elsif(($grade eq "C+")||($grade eq "c+"))
                         {$g = 2.33;}
	              elsif(($grade eq "C")||($grade eq "c"))
                         {$g = 2.00;}
	              elsif (($grade eq "C-")||($grade eq "c-"))
                         {$g = 1.67;}
	              elsif (($SG eq "D+")||($grade eq "d+"))
                         {$g = 1.33;}
	              elsif (($SG eq "D")||($grade eq "d"))
                         {$g = 1.00;}
	              elsif (($SG eq "D-")||($grade eq "d-"))
                         {$g = 0.67;}
	              elsif (($SG eq "F")||($grade eq "f"))
                         {$g = 0.00;}

	              $gp = $g * $unit;
	              $t_unit  += $unit;
	              $t_gp += $gp;

	              print ("\nPlease key in your subject grade:");
	              $grade = <STDIN>;
	              chomp($grade);
	           }

	      $gpa = $t_gp / $t_unit;
	      
	      print ("\nYour GPA of semester $count is = $gpa\n");

	      $pa += $gpa ;

	      if ($count == 1)
	      {
	      $cgpa = $gpa;
	      
              $ocgpa = "c:/J/Sem$count.txt";
              open (OCGPA, ">$ocgpa") or die "cannot open $out for write: $!";
              
	     		  print OCGPA "\n#ID	            GPA	            CGPA\n";
              print OCGPA "\n$ID	            $gpa	            $cgpa\n";
              
              close OCGPA;
              
	      print ("\nYour CCGPA of semester 1 is = $cgpa\n");
	      }
	      elsif ( $count != 1)
	      {
	      $cgpa = $pa/$count;
	      
              $ocgpa = "c:/J/Sem$count.txt";
              open (OCGPA, ">$ocgpa") or die "cannot open $out for write: $!";
              
	     		  print OCGPA "\n#ID	            GPA	            CGPA\n";
              print OCGPA "\n$ID	            $gpa	            $cgpa\n";
              
              close OCGPA;
              
              print ("\nYour CGPA of semester $count is = $cgpa\n");
	      }

	      $t_gp = 0.00;
	      $t_unit = 0.00;
	      
	   } # end for
		        $pa = 0.00;

           
	}  #end if

	elsif($n == 2)
	{
		print "Choose the semester :";
		chomp($cho = <STDIN>);
		
	        $view = "c:/J/Sem$cho.txt";
                open VIEW, $view or die "cannot open $out for write: $!";
                while(<VIEW>){
	                print " $_";
	                }
	               
	               
			
	}

	elsif($n == 3)
	{
	        exit(0);
	}
} #end while

If reprograming is necessary plz go ahead.
Thanks in advance.
  #2  
Old 07-Aug-2007, 07:44
Reny's Avatar
Reny Reny is offline
Junior Member
 
Join Date: Aug 2006
Posts: 58
Reny is on a distinguished road

Re: PERL: Problem with Read from file


i did some research and found something.
However, i dont know how to save the values inside an array to a file correctly.
Can anyone a simple example?
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
random access file read problem wmmccoy0910 C Programming Language 13 19-Aug-2006 02:02
File Read Problem. Size limit? jsmain C++ Forum 19 17-Jul-2006 05:22
File write / read problem Tomb332 C++ Forum 2 12-Jul-2006 01:15
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.