Close
Duke shfaqur rezultatin -9 deri 0 prej 8
  1. #1
    i/e regjistruar Maska e PantherTouch
    Anëtarësuar
    12-02-2004
    Postime
    31

    Unix Shell - Detyrë në shell

    Kam nje assignment n shell dhe nuk di ca me ba se s'po e baj dot. Ene tri dit afat kam. Po e postoj ketu e mase ka noi me mnimu nopak.
    [QUOTE]
    For this assigment you must create a Unix shell script (more precisely a Bourne shell script) that computes grades for a given student for individual courses, based on the performance in individual pieces of work, as well as a GPA. Your program will be called as follows:

    a3

    where "" is a arbitrarily sized list of directories (each corresponding to a course). "" is an arbitrary string, which is guaranteed to uniquely identify a student. However, both the names of the directories as well as the studentId are guaranteed not to contain any form of whitespace. A directory specified on the command line corresponds to a course and each file in such a directory to an assignment, test or exam in a course. Each of these files has the following format. The first line contains the specification of how much each piece of work is weighted. This specification has the format ([CLARIFIED March 1] the two strings are seperated by a single tab character):

    weight

    where the integer specifies the percentage of the course grade. I.e. "weight 5" specifies that this assignment is worth 5% of the course mark. The remaining lines of each file contain the records of student performance and have the following format (the two strings are seperated by a single tab character):



    E.g. the line "cs000000 4" means that the mentioned student got 4 out of 5 on this assignment. Your task is now to compute the performance for the specified student for each specified course and then compute a GPA over all printed grades. The output must be directed to standard output. More precisely, for each course the output must be the name of the course, followed by a tab character, followed by the numeric grade according to the York scale (see below). The last line of the output must be the string "GPA" followed by a tab character, followed by the numeric GPA - truncated to an integer value. See the sample output below for an example.
    [CLARIFIED March 1] Note further, that if the command line contains the name of a file (as opposed to the name of a directory), you must ignore the corresponding arguments. This may happen e.g. through the expansion of wildcard characters, see the example at the bottom. If a directory named on the command line does not exist, you must simply ignore the corresponding argument (do not print any message in this case!). [ADDED March 2] If no argument is valid, you must not print the GPA line (as this prevents a division by 0).
    You are allowed to make the following assumptions (which are guaranteed to be true for all testcases):

    * The weights of all pieces of work for a course always sum to 100. In other words in this context we do not have both a 'weight' and a 'max' or 'out of' for a piece of work. The 'weight' is what the piece of work is out of, and these always total 100 for the course. You are also guaranteed that at least one correctly formatted file exists in each directory.
    * "weight" is not a valid studentId.
    * An absent record means that the student didn't submit the work and you must use a grade of 0 for this piece of work. If all records for a student are absent, then assume that the student received 0 on all pieces of work. This also means that you do not need to worry about mechanisms for weight transfers, etc.
    * You are guaranteed that each file has exactly the format as specified above. I.e. the header line is always present, and each line in the individual files does not have whitespace at the beginning or the end of the line. [ADDED March 8:] You can also assume that individual files do not contain duplicate lines for a student (i.e. two marks for the same piece of work is not possible).

    If the command is called with no arguments, or if the list of directories is not specified, you must print the following message to the standard error stream:

    usage: programmname

    where programmname is the current name of the shell script (which may not be "a3" if the file was renamed). Furthermore, you must print the name of the script without any path components (i.e. "./a3" is incorrect, "a3" is correct).
    [quote]


    Ja dhe shkalla gradimit
    Mark Range
    Numeric Grade
    Letter Grade
    mark >= 90
    9
    A+
    80 <= mark < 90
    8
    A
    75 <= mark < 80
    7
    B+
    70 <= mark < 75
    6
    B
    65 <= mark < 70
    5
    C+
    60 <= mark < 65
    4
    C
    55 <= mark < 60
    3
    D+
    50 <= mark < 55
    2
    D
    40 <= mark < 50
    1
    E
    0 <= mark < 40
    0
    F
    Ja ne nji shemull

    Sample Input/Output
    Assume that the directories COSC1030 and COSC2031 exist in the current directory (and only these) and that the specified files have the content as shown in the table:
    Filename
    Contents
    COSC1030/assignment
    weight 20
    john 15
    sue 20
    COSC1030/test1
    weight 40
    john 30
    sue 30
    COSC1030/test2
    weight 40
    john 31
    sue 40
    COSC2031/a1
    weight 5
    john 4
    johnny 5
    COSC2031/a2
    weight 5
    johnny 3
    COSC2031/a3
    weight 5
    john 2
    COSC2031/a4
    weight 5
    john 5
    johnny 1
    COSC2031/final
    weight 50
    john 40
    johnny 10
    COSC2031/midterm
    weight 30
    john 20

    The command "a3 sue COSC1030" should then produce the output:
    COSC1030 9
    GPA 9
    The command "a3 john COSC1030 COSC2031" should then produce the output:
    COSC1030 7
    COSC2031 6
    GPA 6
    The command "a3 johnny *" should produce the output:
    COSC1030 0
    COSC2031 0
    GPA 0
    [AMENDED March 1] Note that in this example, the wildcard will also match the file "a3", but as filenames on the command line are to be ignored, this doesn't show up in the output. [CLARIFIED March 2] However, the command "a3 johnny a3" should not produce any output.
    Finally, the command "a3 COSC1030 COSC2031" should produce the output:
    COSC2031 0
    GPA 0

  2. #2
    Programues Softueresh Maska e edspace
    Anëtarësuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Finally, the command "a3 COSC1030 COSC2031" should produce the output:
    COSC2031 0
    GPA 0
    Dmth studenti ne kete rast ka qene COSC1030 dhe mqns ky student nuk ekziston ne skedaret e dosjes COSC1031, nota e tij eshte zero. E kam kuptuar qarte kete?
    Edi

  3. #3
    Larguar Maska e cunimartum
    Anëtarësuar
    07-06-2002
    Vendndodhja
    Canada
    Postime
    678
    Do me lesh pa gjume me duket

    1. Lejohen te perfshihen gjuhe programimi formale filtruese si awk apo sed. Ose gjuhe te tjera si Java, perl ose C ???
    2. GPA do llogaritet duke gjetur mesataren e rangeve (perqindje psh. (78 + 65) /2 ) dhe pastaj te gjendet e vlefshmja ne tabele apo duke bere mesataren e numerical grade.
    3. Kam access ne /dev/null (megjithese them qe edhe mund te mos me duhet)

    4. DHe se fundi kodin ta postoj ketu apo te ta dergoj me MP kur ta mbaroj ?
    Fen e ke krejt personale. MEMEDHEUN E KEMI TE PERBASHKET.

  4. #4
    i/e regjistruar Maska e PantherTouch
    Anëtarësuar
    12-02-2004
    Postime
    31
    [quote]
    Dmth studenti ne kete rast ka qene COSC1030 dhe mqns ky student nuk ekziston ne skedaret e dosjes COSC1031, nota e tij eshte zero. E kam kuptuar qarte kete?
    [/quote

    Shume Qart. COSC1030 merret si studenti ne ket rast

    Nuk lejohet asgja tjeter pervec bourne shell /bin/sh,
    gpa do bahet me mesataren e notave numerike ne jo perqindve
    We can assume /dev/null eshte accessible
    Po e bane dot me ke ba nder or vllau ene postoje ktuna se s'kaa problem

    Falemners

  5. #5
    Programues Softueresh Maska e edspace
    Anëtarësuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Ketu e ke dhe skriptin sipas kerkesave qe jane bere me lart.

    - Eshte perdorur vetem Bourne shell (#!/bin/sh)
    Supozohet se:
    - Shuma e pikeve te mundshme te nje kursi eshte gjithnje 100
    - Cdo dosje ka te pakten nje skedar te sakte
    - Shuma e notave te studentit per nje kurs nuk mund te jete me shume se 100

    - Nqs nje student nuk gjendet ne skedaret e nje kursi, vleresimi i tij eshte 0
    - Nqs argumentat mungojne, do shfaqet ky rresht:
    usage: $0
    - Dosjet qe jane te pavlefshme nuk merren parasysh
    - Nqs te gjitha dosjet jane te pavlefshme, do shfaqet ky rresht:
    usage: $0

    - Skripti krijon 2 skedare te perkohshem qe fshihen kur programi mbaron
    emri_i_studentit_temp
    emri_i_studentit_temp2


    Kodi:
    #!/bin/sh
    
    if [ $# -lt 2 ];
    then
    	echo 'usage: '`basename $0`'  ';
    	exit 0;
    fi 
    
    student=$1;
    shift; 
    
    valid_dirs=0;
    course_grade=0;
    course_grades_total=0;
    gpa=0;
    
    while [ $# -gt 0 ];
    do	
    	if [ -d $1 ];
    	then
    		cd $1;
    		
    		valid_dirs=`expr $valid_dirs + 1`;
    		
    		for files in *;
    		do		
    			cat "$files" 2> ../${student}_temp2 | grep "^$student[	][0-9+]" > ../${student}_temp;
    			
    			read < ../${student}_temp keyword score other;
    			
    			if [ "$score" = '' ];
    			then
    				score=0;
    			fi
    
    			course_grade=`expr $course_grade + $score`;
    		done
    
    		cd ..;
    
    		if [ $course_grade -ge 90 ]; then course_grade=9;
    		elif [ $course_grade -ge 80 ]; then course_grade=8;
    		elif [ $course_grade -ge 75 ]; then course_grade=7;
    		elif [ $course_grade -ge 70 ]; then course_grade=6;
    		elif [ $course_grade -ge 65 ]; then course_grade=5;
    		elif [ $course_grade -ge 60 ]; then course_grade=4;
    		elif [ $course_grade -ge 55 ]; then course_grade=3;
    		elif [ $course_grade -ge 50 ]; then course_grade=2;
    		elif [ $course_grade -ge 40 ]; then course_grade=1;
    		else course_grade=0;
    		fi
    
    		course_grades_total=`expr $course_grades_total + $course_grade`;
    
    		echo "$1	$course_grade";
    
    	fi 
    
    	course_grade=0;
    
    	shift;	
    
    done
    
    if [ $valid_dirs -ne 0 ];
    then
    	gpa=`expr $course_grades_total / $valid_dirs`;
    	
    	echo "GPA	$gpa";
    	
    	rm ${student}_temp*;
    else
    	echo 'usage: '`basename $0`'  '; 
    fi
    Ndryshuar për herë të fundit nga edspace : 10-03-2004 më 15:10
    Edi

  6. #6
    Larguar Maska e cunimartum
    Anëtarësuar
    07-06-2002
    Vendndodhja
    Canada
    Postime
    678
    Edspace e paske postuar me shpejt.
    Ja pra dhe versioni im.

    Kodi:
    command=`basename "$0"`	#	Extract the exact name of the command out of its full path 
    
    #	Set the GPA and the number of courses to 0
    GPA=0
    numOfCourses=0
    
    #	If there are no arguments to a or only one argument that is not a directory,
    #	display "how to use a3" 	   
    case $# in
    0)	echo "usage: $command  "; 1>&2; exit 2;;
    1)	
       if [ ! -d "$1" ]
       then
          echo "usage: $command  "; 1>&2; exit 2
       fi ;;
    esac
    
    #	Pass the first argument to studentID and shift to the second 
    #	(which if valid should be a directory) to be used after
    studentID="$1"
    shift
    
    #	Loop on each directory, "act" on it and then apply "shift" to make
    #	the second argument available to the loop.
    for i
    do
       total=0
       checker=1
       curDir=`pwd`	
       if [ -d "$1" ]		# "Act" on it only if it is a regular directory
       then
          cd "$1"			# Enter the directory and "act" on each file of it
          for eachFile in *
          do
             if [ -f "$eachFile" ]	# "Act" on each file only if it's a regular one
             then
             # Set $isValid to "weight" for testing if the first line contains the header.
             # If so cut the weight and the mark for that student out of the file and 
             # assign them to $weight and $mark. If no mark entry assign him/her a 0  
                isValid=`cat "$eachFile" | grep -n "^weight	" | cut -f1`
                if [ "X$isValid" = "X1:weight" ]
                then
                   checker=0
                   weight=`cat "$eachFile" | grep "weight	" | cut -f2`
                   mark=`cat "$eachFile" | grep "$studentID	" | cut -f2`
                   if [ ! $mark ]
                   then
                      mark=0
                   fi
                   total=`expr $total + $mark`	# Calculate the total mark for each piece of work
                fi
             fi
          done
          cd $curDir	# Return to the original directory
       fi
       # Only if at least one file was valid get the corresponding numerical grade for the
       # corresponding percentage and display the course name followed by the mark
       if [ $checker = 0 ]
       then
          let numOfCourses=numOfCourses+1
          if [ $total -ge 0 ] && [ $total -lt 40 ]; then finalMark=0
          elif [ $total -ge 40 ] && [ $total -lt 50 ]; then finalMark=1
          elif [ $total -ge 50 ] && [ $total -lt 55 ]; then finalMark=2
          elif [ $total -ge 55 ] && [ $total -lt 60 ]; then finalMark=3
          elif [ $total -ge 60 ] && [ $total -lt 65 ]; then finalMark=4
          elif [ $total -ge 65 ] && [ $total -lt 70 ]; then finalMark=5
          elif [ $total -ge 70 ] && [ $total -lt 75 ]; then finalMark=6
          elif [ $total -ge 75 ] && [ $total -lt 80 ]; then finalMark=7
          elif [ $total -ge 80 ] && [ $total -lt 90 ]; then finalMark=8
          elif [ $total -ge 90 ] then finalMark=9
          fi
          echo "$i	$finalMark"
          GPA=`expr $GPA + $finalMark`	# Add each course's mark to GPA to get the avg. after
       fi
       shift
    done
    # Only if there was at least one valid course compute the average and display it.
    if [ $numOfCourses -ne 0 ]	
    then 
       GPA=`expr $GPA / $numOfCourses`
       echo "GPA	$GPA"
    fi

    Kujdes se tek specifikimet mesa lexova une thote qe emri i programit duhet te jete JO pathi i plote pra jo $0 prandaj duhet te perdoresh


    Ja dhe nje script per ta testuar

    Kodi:
    #!/bin/sh
    
    PATH=":$PATH"
    
    command=`basename "$0"`	#	Extract the exact name of the command out of its full path 
    
    #	If there are no arguments to testoA3 display:
    case $# in
    0)	echo "usage: $command  "; 1>&2; exit 2;;
    1) echo "usage: $command  "; 1>&2; exit 2;;
    esac
    echo -n "">tester.log
    com=$1
    dir=`pwd`
    if [ -d $2 ]
    then
       cd $2
       echo "Testing <$testDir> with $com john"; $com john >>$dir/tester.log
       echo "Testing <$testDir> with $com"; $com >>$dir/tester.log
       for testDir in *		# testingDirectories will be looped
       do
          if [ -d  $testDir ]
          then
             cd $testDir
             echo "Testing <$testDir> with $com john *";  $com john * >>$dir/tester.log
             echo "Testing <$testDir> with $com john /"; $com / >>$dir/tester.log
             echo "Testing <$testDir> with $com john /bin"; $com john /Documents >>$dir/tester.log
             echo "Testing <$testDir> with $com john /usr *"; $com john /Documents * >>$dir/tester.log
             echo "Testing <$testDir> with $com /usr john *"; $com /usr john * >>$dir/tester.log
             
          cd ..
          fi
       done
    fi
    cd $dir
    echo "Ndryshime... nese ka !"
    diff tester.log expected

    do bashkangjis edhe nje direktori me teste
    Skedarët e Bashkëngjitur Skedarët e Bashkëngjitur
    Fen e ke krejt personale. MEMEDHEUN E KEMI TE PERBASHKET.

  7. #7
    i/e regjistruar Maska e PantherTouch
    Anëtarësuar
    12-02-2004
    Postime
    31
    Falemneres oj cuna se paski qen mjeshtra.
    I mora kodet dhe e kam tqart iden, do e baj edhe i her vet se deri diku kisha shku por tani e kam shum tqart.
    Falemner edhe per test script, do jet ma e leht

    Ju jam borxhli shnet

  8. #8
    Programues Softueresh Maska e edspace
    Anëtarësuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Panther,

    Nuk e di kur e kopjove kodin tim por sigurohu qe ke marre kopjen e fundit sepse bera ate ndryshimin qe me tha cunimartum per `basename $0`
    Sigurohu qe ne fillim dhe ne fund te programit, rreshti i menyres se perdorimit eshte si me poshte:
    Kodi:
    echo 'usage: '`basename $0`'  ';
    Ketu ke dhe komentet ne shqip per funksionin e te gjithe rreshtave
    Kodi:
    #!/bin/sh
    
    # nqs nuk jane dhene te pakten 2 argumenta (studenti, dosja), 
    # printo menyren e perdorimit
    if [ $# -lt 2 ];
    then
    	echo 'usage: '`basename $0`'  '; 
    	exit 0;	# mbylle programin
    fi 
    
    
    student=$1;	# merr emrin e studentit nga argumenti i pare
    shift;		# fshije emrin e studentit nga lista e argumentave
    
    valid_dirs=0;	# numri i dosjeve qe jane te vlefshme (kurset)
    course_grade=0;	# shuma e notave te nje kursi
    course_grades_total=0;	# shuma e mesatareve te te gjitha kurseve
    gpa=0;	# mesatarja e te gjithe kurseve
    
    while [ $# -gt 0 ]; # per cdo argument pas emrit te studentit
    do	
    	if [ -d $1 ];	# nqs dosja eshte e vlefshme
    	then	
    		cd $1;	# hape dosjen
    		
    		valid_dirs=`expr $valid_dirs + 1`; #rrite numrin e dosjeve te sakta
    		
    		for files in *; #per cdo skedar brenda dosjes
    		do		
    			# gjej vetem rreshtat qe kane: 	
    			# ruaji ne skedarin _temp
    			# nqs ka gabime hidhi ne skedarin _temp2 qe te mos dalin ne ekran
    			cat "$files" 2> ../${student}_temp2 | grep "^$student[	][0-9+]" > ../${student}_temp;
    			
    			# hap skedarin dhe merr tre fjale
    			# keyword = emri i studentit
    			# score = nota e studentit
    			# other = tekst tjeter qe mund te jete pas notes se studentit
    			read < ../${student}_temp keyword score other;
    			
    			if [ "$score" = '' ];	# nqs nuk gjendet asnje note per studentin
    			then
    				score=0;	# zere noten 0
    			fi
    
    			course_grade=`expr $course_grade + $score`;	# ruaj shumen e pikeve per kete kurs
    		done	# tani mbaruam me te gjithe skedaret brenda dosjes
    
    		cd ..;	# mbylle dosjen
    
    		# llogarit noten perfundimtare per kursin 
    		# nqs shuma >= 90 atehere nota = 9
    		#  ose nqs shuma >= 80 atehere nota = 8
    		#    ose nqs shumta >=75 atehere nota = 7
    		#      ..........
    		if [ $course_grade -ge 90 ]; then course_grade=9;
    		elif [ $course_grade -ge 80 ]; then course_grade=8;
    		elif [ $course_grade -ge 75 ]; then course_grade=7;
    		elif [ $course_grade -ge 70 ]; then course_grade=6;
    		elif [ $course_grade -ge 65 ]; then course_grade=5;
    		elif [ $course_grade -ge 60 ]; then course_grade=4;
    		elif [ $course_grade -ge 55 ]; then course_grade=3;
    		elif [ $course_grade -ge 50 ]; then course_grade=2;
    		elif [ $course_grade -ge 40 ]; then course_grade=1;
    		else course_grade=0;
    		fi
    
    		# mblidh notat e te gjitha kurseve
    		course_grades_total=`expr $course_grades_total + $course_grade`;
    
    		echo "$1	$course_grade";	# printo 
    
    	fi 
    	
    	course_grade=0;	# ktheje noten e kursit ne 0 sepse mbaruam
    
    	shift;	# fshije kete kurs dhe hidhu tek tjetri
    
    done	# mbaruan te gjithe argumentat e dosjeve
    
    if [ $valid_dirs -ne 0 ];	# nqs kemi te pakten nje dosje te vlefshme
    then
    	gpa=`expr $course_grades_total / $valid_dirs`;	# llogarit mesataren
    	
    	echo "GPA	$gpa";	# printo mesataren ne ekran
    	
    	rm ${student}_temp*;	# fshi skedaret e perkohshem qe krijuam me lart
    else	# nqs te gjitha dosjet ishin te pavlefshme 
    	# printo menyren e perdorimit: 
    	# `basename $0` printon emrin e skriptit
    	echo 'usage: '`basename $0`'  '; 
    fi
    Edi

Tema të Ngjashme

  1. Fizike: Si te gjej dendesine e ajrit ne dhomen time?
    Nga vaalmir në forumin Mentori akademik
    Përgjigje: 16
    Postimi i Fundit: 05-11-2014, 11:18
  2. Kam nevoje per nje detyre kursi ne SHqip me tematike ekonomike
    Nga Gunnar në forumin Ndihmoni njëri-tjetrin
    Përgjigje: 0
    Postimi i Fundit: 26-05-2006, 02:27
  3. Diplomacia, një detyrë e vështirë
    Nga Albo në forumin Kulturë demokratike
    Përgjigje: 1
    Postimi i Fundit: 22-05-2006, 13:42
  4. Ofertat me te reja per pune
    Nga ganoid në forumin Ekonomi & biznes
    Përgjigje: 27
    Postimi i Fundit: 21-01-2005, 13:30
  5. Leke Dukagjini
    Nga shendelli në forumin Historia shqiptare
    Përgjigje: 8
    Postimi i Fundit: 10-05-2003, 11:19

Regullat e Postimit

  • Ju nuk mund të hapni tema të reja.
  • Ju nuk mund të postoni në tema.
  • Ju nuk mund të bashkëngjitni skedarë.
  • Ju nuk mund të ndryshoni postimet tuaja.
  •