COMP1511 17s1 Introduction to Programming

Objectives

In this Lab, you will practice:

Preparation

Before the lab you should re-read the relevant lecture slides and their accompanying examples. You should also have read the lab assessment guidelines.

Getting Started

One member of your programming pair should login and run the following commands inside a Linux terminal

Create a new directory for this lab called lab11 by typing:

mkdir lab11
Change to this directory by typing:
cd lab11

Exercise: Converting COMP1511 Lab Grade Into a Mark

Each week you recieve one of 5 grades for a COMP1511 lab exercise. The following table lists the grades.

The table also has an (indicative) mapping for each grade to an individual mark.

Grade Criteria Mark
A+ Complete, correct, and clear solution - if there are challenge exercises a good attempt on these must be made 1.25
A Competent solution to standard lab exercises 1.1
B Most of standard lab exercises completed, to all completed but with one or more major bugs 0.8
C Partial solution only, most of lab not completed 0.5
. Not attempted .

Write a C program grades2labmark.c which takes a single command line arguments, a string of lab grades. It should print the corresponding total lab mark to one decimal place. Remember your lab mark can not exceed 10. For example:

dcc grades2labmark.c -o grades2labmark
./grades2labmark CAA.A+A+ABCBA
9.5
./grades2labmark ABABAA+BBABA+
10.0
./grades2labmark CA+..B..BBCA+
5.9
Don't assume any particular number of lab grades in the string (there are actually 10 assessable labs this session).

Hint: place your code to calculate the lab mark in a function with this prototype:

double grades2labmark(char grades[]);
And create a simple main function which calls grades2labmark.

You'll want to reuse grades2labmark in the next exercise.

As usual autotest is available to help you test your program.

 ~cs1511/bin/autotest lab11 grades2labmark.c

Exercise: Printing Lab Marks

The file labmarks.txt contains the lab marks for COMP1511 students.

The file print_labmarks.c contains a C code to read this information into a linked list of structs. It is given one command-line argument, the name of the marks file.

Modify print_labmarks.c so that it prints the lab marks for all students in a specified class. The name of the lab class will be specified as a second command-line argument.

Start by copying the two files:

cp /import/chopin/1/cs1511/public_html/17s1/tlb/11/print_labmarks.c .
cp /import/chopin/1/cs1511/public_html/17s1/tlb/11/labmarks.txt .
head labmarks.txt
5082094 Jonathan Liang wed13-sitar .ABC..B.ACB
5025147 Yishuang Feuer thu09-sitar CA+CBACC.A+CB
5048284 Chao Caamwang mon17-kora A+CB..AA.BCA
5003054 Michael Ganguly fri12-oboe BBCA+A+A+.ABBB
5006842 Darshan Gupta tue18-flute A+A+.BAA+BABCB
5066309 Alfred Tao tue12-sitar B.A+A+AAACA+A+.
5078835 Phillip Cai tue15-oboe CBA+A.A+BA+.CC
5062191 Emily Koh mon17-kora A+BABA+BA.A.A
5006921 Jurun Ping tue12-oboe .C.CABABCAA
5070065 Aayushma Cohen wed13-oboe CBCCB.BAA+A+A

Here is how print_labmarks.c should behave after your changes:

dcc print_labmarks.c -o print_labmarks
./print_labmarks labmarks.txt tue09-kora
5063177 Morgan Huynh                   tue09-kora   A+.B.AA..AC.            5.8
5097719 Kah Li                         tue09-kora   BCABA.CBA+A+A+          9.4
5024788 Raymond Lim                    tue09-kora   A+CA+AA+A+A+BA+A+C     10.0
5039227 Haosu Kwong                    tue09-kora   B.CCBACCA.A+            7.1
5087364 Timotius Yu                    tue09-kora   A+.A+BC.ABC.C           6.7
5072336 Liyee Henoch                   tue09-kora   AAA.AB.A+A+AB           9.6
5057497 Zhengyu Wang                   tue09-kora   BAA+BCACCCA.            8.2
5071465 Xiaohan Cao                    tue09-kora   BCC.ABCBAA+A            8.4
5016202 Yijia Davis                    tue09-kora   CA+..CCCA+CBB           6.6
5002493 Song Li                        tue09-kora   AA+ABB.BABAA            9.9
5044859 Guanting Davidson              tue09-kora   A+AA+A+.CAA+BA+A       10.0
5068224 David Huang                    tue09-kora   C.AABA...A+.            5.8
5039893 Bhawna Sun                     tue09-kora   CBBAC.BA+.AC            7.3
5079069 James Tran                     tue09-kora   A+A+AA+..B.B..          6.4
5011466 Kevin Wang                     tue09-kora   A+.BABA+..C.C           6.2
5060552 Abdullah Devathi               tue09-kora   CB..A+A+A.BA.           6.8
5054357 Emmanuel Ghatak                tue09-kora   .CACBAA+AAA+A           9.8
5047380 Nancy Zhong                    tue09-kora   B..ACBC.A+C.            5.5
5002062 Christopher Wu                 tue09-kora   A+CA+A+CBCB..C          7.3
5033947 Carey Charlton                 tue09-kora   CA+CACCBA+...           6.4
5094267 Brendan Jillani                tue09-kora   AB.BCAAACA.             8.1
5026044 William Tejero                 tue09-kora   .BBA+.A+CA+B.A          7.8
5009976 Renjie Xue                     tue09-kora   AA+AAB..BCA+B           8.7
5040965 Vincent She                    tue09-kora   BAA+A.BA+.BB.           7.9
5052488 Hong Agapitos                  tue09-kora   BB...AB.AAA+            6.9
5023273 Caleb Phuenghansaporn          tue09-kora   A+BAAAAC.BA+A          10.0
5028543 Daksh Gao                      tue09-kora   AA+CB.CCA+CA+C          8.2
5042895 Da Dong                        tue09-kora   BA+A+.A+BBAABA+        10.0
5077748 Guhan Kim                      tue09-kora   BBBABA+CB.AA            9.1
5099218 Rahil Eager                    tue09-kora   AA.AA+AA+.A+A+B        10.0
5069640 Buyang Chin                    tue09-kora   B...A+A+A+BCBA+         7.9
You must also add code to print_labmarks.c which calls free to release all the memory allocated for student structs with malloc.

Do not read any input. Do not call fscanf, fgets etc. Do not create any arrays or other linked lists. Just use the linked list returned by the read_students_file function in the code you are given in print_labmarks.c

Hint: the code you are given in print_labmarks.c just takes one command-line argument (the name of the marks file). Change it to take 2.

Hint: this printf format might be useful: "%d %-30s %-12s %-22s %4.1lf\n".

Hint: copy the grade2mark function into print_labmarks.c (autotest is expecting only this file)

As usual autotest is available to help you test your program.

 ~cs1511/bin/autotest lab11 print_labmarks.c

Challenge Exercise: Sorting Students

Create a C program sort_students.c which, given a lab marks file as a command-line argument, prints the students in sorted order.

You must use the code you are given in print_labmarks.c to read the file.

You must rearrange the linked list returned by read_students_file into sorted order and then print it.

You can not use arrays in your code.

You can not use malloc in your code (except for the call to malloc in read_student).

You must reorder the linked list returned by read_students_file and then print the list.

Students should be ordered firstly on last name. If they have the same last name they should be ordered on first name. If this is also the same they should be ordered on zid.

You can assume students only have two names.

Make you program match the following example exactly:

dcc sort_students.c -o sort_students
./sort_students labmarks.txt
5080641 Joshua Abayasingam             wed13-kora   BBCA+CBBBBBB            8.7
5075388 Edbert Adhikara                mon13-sitar  ACA..A+A+A+BAC          8.8
5096572 Saeed Adjei-Yeboah             tue09-sitar  AA+C.CCA+.CA+A          7.9
5093918 Haocheng Agapiou               tue15-sitar  CA+.CA+A+BBAA.          8.5
5051260 Yiwei Agapiou                  thu17-kora   A+C.ABA+A+A.AA+         9.6
5052488 Hong Agapitos                  tue09-kora   BB...AB.AAA+            6.9
5071624 Thomas Agapitos                tue15-sitar  .A+CCC.BCA+CB           6.6
5026321 Amanda Aggarwal                thu09-sitar  AA+.AAABA+.A+A         10.0
5092895 Joshua Agius                   fri12-sitar  BA+A+BAA+CCC.A+         9.2
5018595 Abdullah Agrawal               fri09-oboe   A+A+A+A+A+CAA+AAA+     10.0
...
5063193 Edbert Zhou                    mon13-oboe   CCCAACACBAA             8.8
5046373 Franklin Zhou                  fri09-kora   A+ABBA.CA+CBC           8.6
5069868 Jacob Zhou                     tue18-flute  A+B.BA...CBA            6.3
5022608 Maxwell Zhou                   tue12-kora   .ACA.A+.CCCA            6.6
5044229 William Zhou                   tue15-oboe   A+BCA+CA.A+A+CB         9.2
5037555 Yinuo Zhou                     thu09-sitar  A+CA+B..AA+..C          6.7
5047970 Alyne Zhu                      tue09-oboe   A+BABBA+.A+A+BA        10.0
5009758 Sang-Hoon Zhu                  fri12-oboe   .CACCA..A+AB            6.9
5083232 Jessica Zong                   mon17-sitar  .B.AABC.ACC             6.4
5082060 Nicholas Zong                  thu13-kora   AA+ABB.CCA+AA+          9.7
As usual autotest is available to help you test your program.
 ~cs1511/bin/autotest lab11 sort_students.c

Submission/Assessment

When you are satisfied with your work, ask your tutor to assess it. You also need to submit your work electronically by typing (run this command in the lab11 directory):
give cs1511 lab11 grades2labmark.c print_labmarks.c sort_students.c
Submit the challenge exercises only if you attempt them.

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember the lab assessment guidelines - if you don't finish the exercises you can finish them in your own time, submit them by Monday 11:00am using give and ask your tutor to assess them at the start of the following lab.

Either or both members of a programming pair can submit the work (make sure each program lists both of you as authors in the header comment).