0% found this document useful (0 votes)
59 views25 pages

ISE 101 Projects J

The document describes a project on matrix operations that involves writing functions to generate and destroy matrices, compare matrices, transpose a matrix, and multiply matrices. Students are instructed to write the functions in a single C file named with their surname and return it by a specified date. The functions will be rigorously tested to check for valid parameter handling and edge cases.

Uploaded by

yourrock
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views25 pages

ISE 101 Projects J

The document describes a project on matrix operations that involves writing functions to generate and destroy matrices, compare matrices, transpose a matrix, and multiply matrices. Students are instructed to write the functions in a single C file named with their surname and return it by a specified date. The functions will be rigorously tested to check for valid parameter handling and edge cases.

Uploaded by

yourrock
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ISE 101 Projects

1.
1 Matrix operations (C)
2. Simple database (C)
3. Linked lists (C)
4. Game of numbers (python)
5. Multiple mp3 finder (python)
6. Matrix operations (python)
7. Ascii art generator (python)
8
8. Oth ll with
Othello ith GUI ((python)
th )
Project 1 ‐ Matrix operations
Due: 21/02/2008 17:00

Return your project files as a single c file. As filename use


your surname. For example kamasak.c

Use ninova for returning your project

I will assign office hours for course assistant for your


questions. Check ninova for the office hours.

February 15, 2008 Lecture 1 1


Project 1 – Matrix operations
• In this project
project, you have to write a set of functions
• We’ll define a structure called matrix_str as follows
struct
t t matrix_str
t i t {
int nrow; /* number of rows in the matrix */
int ncol; /* number of columns in the matrix */
double** matrix; /* matrix elements */
};
• Function 1:
struct matrix_str* generate_matrix(int nrows,int ncols);

This ffunction
Thi ti willill allocate
ll t memory ffor a matrix
t i structure.
t t
Then it will allocate memory for a matrix of size nrows x
ncols It returns the address of the structure
ncols. structure.
February 15, 2008 Lecture 1 2
Project 1 – Matrix operations
• Function 2:
void destroy_matrix(struct matrix_str*);
This function will free the allocated memoryy for the
elements of the matrix. Then it will free the memory
allocated for the struct.
• Function 3;
int compare_matrices(struct matrix_str*, struct
matrix str*);
matrix_str*);
This function compares the sizes and elements of the
matrices and returns 1 if they are equal, 0 if they are not
equal

February 15, 2008 Lecture 1 3


Project 1 – Matrix operations
• Function 4:
struct matrix_str* transpose_matrix(struct matrix_str*);
This function will be given a matrix structure. It creates a
new matrix structure that is the transpose of the given
matrix. The matrix that is passed to this function should
be destroyed.
destroyed Its pointer value should be NULL at the
return
• Function 5;
struct matrix_str* multiply_matrices(struct
matrix_str*, struct matrix_str*);
This function multiples two given matrices. The result is
returned in a new matrix structure. If there is any
problem with the matrices, the return value should be
NULL
NULL.
February 15, 2008 Lecture 1 4
Project 1 – Matrix operations
• Your functions will be checked rigorously
rigorously. Make sure you
always control the passed parameters to see if they are
valid.
• For example, I can always test your functions with a
matrix of negative dimensions, NULL matrix pointers etc.
• Please write all these functions in a single file named with
your surname such as kamasak.c
• Before returning in your functions, make sure it compiles.

February 15, 2008 Lecture 1 5


Project 2 – Simple database

Due: March 13, 2008

Due: March 13, 2008 Project 2 1


Assume the following file format
# this is a comment line discard this line

# number of records in the file


3
# records start from here
04001020 ; Ali Gel; 20 ; 34; 100
04001032 ; Veli Git; 36 ; 23; 57
04002123 ; Ferhat Can; 44 ; 46 ;90

• Any line starting with a “#” is a comment line, your program should not
process these lines
• First integer in the file is the number of records in the file
• Each record has 5 fields: student number
number, student name and surname
surname,
midterm grade, project grade, final grade.
• Fields are separated with semicolons.
• You should read these records from a file and populate structure array
Due: March 13, 2008 Project 2 2
Project 2
struct student_record {
long int id;
char name[128];
double midterm;
double project;
double final
};

Subroutine 1:
struct student_record *sr populate_from_file(char *filename,int *number_read);

This function should read the records from file with the passed “filename”, allocate enough
space for an structure array. Assign the student information to the structure, and return the
structure array pointer. Upon the return number_read should point to the number of records
read from the file.
file

If the number of records is more than the number given in the beginning of the file, the
subroutine should stop at the given number of records.

Due: March 13, 2008 Project 2 3


Project 2
Subroutine 2:
int dump_to_file(char *filename, struct student_record *sr, int number_of_records);

This subroutine should write the student records to the file with the p
passed “filename” usingg
the same format described (number of records, then the record fields seperated with
semicolons). Each line should contain one record. The function should return the number of
records written.

Subroutine 3:
struct student_record * search_by_id(struct student_record *sr, int number_of_records, int
id);

This subroutine should go through the student records searching for a student with the
passed id.
id The subroutine should return the address of the student record that matches the
passed id. If nothing matches it should return NULL.

Due: March 13, 2008 Project 2 4


Project
Subroutine 4:
int search_by_name(struct student_record *sr, int number_of_records, char *name);

This subroutine should ggo through


g the student records searchingg for a student with the
passed “name”. It should return the number of students whose name (or surname) matches.
The search shoud be case insensitive. For example if “ahmet” is sent, it should count the
names “Ahmet”, “aHMet” etc.

Subroutine 5:
int compute_number_of_failing_students (struct student_record *sr, int number_of_records,
int passing_grade);
)

This subroutine calculate the total grades of all students. The total grade is calculated by
weighting
i hti midterm
idt b
by 0
0.2,
2 projects
j t b by 0
0.4,
4 andd fi
finall with
ith 0
0.4.
4 SSo a student
t d t who
h gott 30 ffrom
midterm, 50 from projects, and 80 from final should have total grade of
30*0.2+50*0.4+80*0.4=58. The subroutine should count the number of students whose total
grade is less than (not less than or equal) the passed “passing grade” and return this number.

Due: March 13, 2008 Project 2 5


Project 3
Linked lists
Due: March 28, 2008

March 14, 2008 Lecture 5 1


struct node {
double number;
struct node *prev;
struct node *next;;
};

1. struct node* create_node(double


( number))
This function should allocate memory for a node and initialize its number to the passed
argument. Both links (prev/next) should be initialized to NULL. Function should return the
pointer of the created node.

2. struct node* delete_node(struct node* dnode)


This function should delete (deallocate memory) the node passed as the argument and
connect the rest of the list accordingly
delete

March 14, 2008 Lecture 5 2


Project 3
3. struct node* insert_node(struct node *curPtr, struct node *newPtr,int position)
This function should insert the new node to the list in the given position. If position=‐1, new
node should be inserted before the node (curPtr). If position=1, new node should be inserted
after the node (curPtr). It should return the pointer to the head node of the list.

curPtr

position=‐1 position=1

4. struct node* read_from_file(char *filename);


This function should read a list of numbers from a file seperated by white space/return into a
double linked list and return the head pointer of the list
list.

5. struct node* read_from_file_sorted(char *filename, int order)


This function should read a list of numbers from a file seperated by white space/return into a
sorted (if order=0 ascending,
ascending order=1 descending) double linked list and return the head
pointer of the list.

March 14, 2008 Lecture 5 3


Project 3
5. void print_list(struct node* listPtr);
This function should print the numbers inside the list.

March 14, 2008 Lecture 5 4


Python project

Due: April 4, 2008


Write a number game script that works as follows:
1. Game will generate a 5 digit random number. (Use random
module)
2. Digits of this number should be different from each other.
3 Game should ask a number from the user
3. user.
4. When the user enters a number (again no digits of the entered
number should be same. If there are repeated digits, game
should warn the user) , game should compare this number with
the number that it has generated.
5. Game should give a feedback as: + number of digits guessed at
the correct place, ‐ number of digits guessed at a wrong place.
6. For example: If the game generated 165043 and the user
guessed 140789,
140789 it should return (+1 ‐2),
2) since digit “1”
1 is in its
correct place (+1), digits “4” and “0” are in wrong places (‐2).
7. Game should keep track of number of guesses. When the user
guess the number correctly it should congratulate the user and
print the number of guesses.
Sample screen output:
Enter a number: 0
1 : Invalid number
Enter a number: 125
2 : Invalid number
E t a number:
Enter b 123456
2 : [0, 4]
Enter a number: 3456789
4 : Invalid number
Enter a number: 345678
4 : [0, 2]
Enter a number: 987651
5 : [0,
[0 2]
Enter a number: 456123
6 : [1, 3]
Enter a number: 412398
7 : [3, 2]
Enter a number: 412567
8 : [1, 2]
Enter a number: 712398
9 : [2, 2]
Enter a number: 412356
10 : [2, 2]
Enter a number: 412397
11 : [3, 2]
Enter a number: 478395
12 : [3, 0]
Enter a number: 412390
13 : [3, 3]
Enter a number: 401392
14 : [6, 0]
congratulations, you guessed at 14 trials
Project 5 ‐ Due: April 17 2008, 18:00
• Write a python script that finds the mp3 files that have
multiple copies below a given directory (including subfolders).
• Decision is made upon comparing file name and file size.
• If both are same for two files then they are assumed to be
same and the user is warned for a duplicate mp3 file.
• For example:
>>> find_duplicate_mp3(‘C:\my music’)
>>> Warning: Sting‐Shape of my Heart.mp3 size: 6523425 is found at
C:\my music\Sting
C:\my music\Yabanci
C:\my music\Misc
Project 6, Due: April 22, 2008 18:00
• Complete save,
save multiply and transpose methods in the
given Python script that is uploaded to Ninova

April 11, 2008 Lecture 8 1


ISE 101 Project 7, Due: May 9 2008
• Write a python script that reads a jpeg file and creates
ascii art from the image file.
Output
Input
Reading JPEG files
• Install Python imaging library from
http://effbot.org/downloads/PIL‐1.1.6.win32‐py2.5.exe
• Use this library
from PIL import Image
img=Image open('a1
img=Image.open( a1.jpg
jpg')
)
nrow,ncol=img.size
asciichars =["@", "#", "+", "*", ";", ":", ",", ".", "`", " "]

• According to the value of a pixel, assign one of the


characters from asciichars
• The output should be formatted as HTML file so that it
can be viewed from a browser
Output HTML
f
from PIL i
import Image

img=Image.open(‘beyaz.jpg')

nrow,ncol=img.size

asciichars =["@", "#", "+", "*", ";", ":", ",", ".", "`", " "]
#asciichars =["#", "@", "Q", "X", "W", "O", "K", "p", "i"]

fid=open(‘beyaz.html','w');
fid.write('<HTML>\n')
fid.write('<echo>\n')
fid.write('<body bgcolor=#8080ff>\n')
fid.write('<font color=white>\n')
fid.write('<pre style="font: 9px/9px Courier New;">\n')

#
# Go through each element of the image and write one of the
# ascii chars according to the value of the image pixel.
# For highest values (brighter pixels) put @
# For lowest values (darkest pixels) put white space
#
#
print img.getpixel((100,100))

fid.write('</pre>\n')
fid.close();
Othello with Graphics
• Write reversi or othello on a 8x8 board
• For game rules see
http://en wikipedia org/wiki/Reversi
http://en.wikipedia.org/wiki/Reversi
• Game will be played between 2 players, NOT against
computer
p
• For a simple GUI see the simpleGUI.py
• simpleGUI.py uses a graphic library named graphics.py
• For more information on the graphics library see
graphics.pdf at Ninova
• This project is OPTIONAL and will count for 50% of your
final exam grade.
• You have to turn it in before taking your ISE101 final
exam.

You might also like