Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

GAZİ UNIVERSITY 2019-2020 SPRING SEMESTER (ONLINE EDUCATION)

CE 102 – COMPUTER PROGRAMMING


Dr. Murat Ayhan & Dr. Güneş Babagiray
FINAL ASSIGNMENT
Start  15.06.2020 – 18.00 End  15.06.2020 – 23.00
Requirements:
1. You must send your solutions before 23.00 (on 15.06.2020). Any files submitted later than this time
will NOT be graded. Please do not wait for the last minute to send your files.
2. You must send your solution files simultaneously to:
a. muratayhan@gazi.edu.tr
b. pandemifinal@gazi.edu.tr
c. Upload to GUZEM (Perculus) System
If you do not upload your files to mentioned e-mails and Perculus system on time, the instructors
will not be responsible of any transfer problems.
3. Please submit your solutions in one single “WORD” file. You can also upload the “PDF” version
of that Word file.
a. All 4 solutions of questions should be on the SAME file.
b. DO NOT send .m (Matlab) files. They will NOT be graded. Send as WORD / PDF file.
c. The solutions require you to send commands in the Command Window, functions in the
Editor Window, and visual outputs (i.e. graph). You can copy the commands in the
Command Window and functions in the Editor Window as text to your Word file. Or, you
can attach an image of your MATLAB screen (the image should include all parts related to
the solution). However, the only way to attach your visual output (i.e. graph) is to copy it
as an image to your Word file. Please be sure that your images are sufficiently visible.
4. You must save your file as follows:

“Gazi_Insaat_CE102_Final_StudentName_StudentSurname_StudentID”
For example  “Gazi_Insaat_CE102_Final_Sergen_Yalçın_181130093”
5. Make sure your files can be opened!! Some students tend to send broken files deliberately so that
they can replace the broken file on a later day by contacting the instructor. This will NOT be
tolerated. You have to control your files (i.e. send to your e-mail first and open it in another device).
6. Plagiarism and copying are STRICTLY FORBIDDEN! Even small similarities may cause your
final work to be faulty and such files WILL NOT BE GRADED! Necessary administrative
measures will be taken for plagiarism and copying.
7. This final assignment consists of 4 questions on 4 different pages. Please read the questions
carefully. Do not miss any thing the solution requires. If a method is declared to be used or not to
be used in a solution, please solve it accordingly. Otherwise, they will not be graded.
FINAL ÖDEVİ
Başlangıç  15.06.2020 – 18.00 Bitiş  15.06.2020 – 23.00
Gereklilikler:
1. Final ödevinizin cevaplarını içeren dosyayı 15.06.2020 tarihi saat 23.00’dan önce göndermeniz
gerekmektedir. Bu tarih ve saatten geç gönderilen dosyalar değerlendirmeye alınmayacaktır. Lütfen
ödevinizi yüklemek için son dakikayı beklemeyiniz. Ödev süresi olan 5 saat fazlasıyla yeterli
olacaktır.
2. Final ödevi dosyalarınızı “aynı anda” aşağıdaki iki e-posta adresinin yanı sıra GUZEM sistemine de
yüklemeniz gerekmektedir.
a. muratayhan@gazi.edu.tr
b. pandemifinal@gazi.edu.tr
c. GUZEM (Perculus) Sistemine yükleme
Eğer dosyalarınızı belirtilen üç adrese de zamanında yüklemezseniz, dersin yürütücüleri dosya
transferleri hususunda yaşanabilecek aksaklıklar hakkında herhangi bir sorumluluk kabul
etmeyecektir.
3. Final ödevinizi tek bir “WORD” dosyası olarak gönderiniz. Aynı, Word dosyasının “PDF”
versiyonunu da yükleyebilirsiniz.
a. Ödevde bulunan tüm soruların (4 soru) cevaplarını aynı dosya (tek Word veya PDF)
içerisinde gönderiniz.
b. MATLAB uzantılı (.m) dosya göndermeyiniz. Bu dosyalar notlandırılmayacaktır.
c. Çözümlerinizde Komut Ekranından komutlar, Editör Ekranından fonksiyonlar veya Figür
Pencerelerinden grafikler göndermeniz gerekecektir. Komutları ve fonksiyonları metin
olarak Word dosyanıza kopyalayabileceğiniz gibi, (MATLAB ekranınızın çözümle alakalı
tüm kısımlarını içermek kaydıyla) görüntü dosyası olarak da Word dosyanıza
kopyalayabilirsiniz. Bu durumda görüntünün kalitesinin yeterli okunurlukta olduğuna emin
olun. Ancak, grafiğinizi Word dosyanıza aktarmanın tek yolu, grafiği görüntü olarak Word
dosyasına aktarmak olacaktır.
4. Dosyanıza aşağıdaki formatta isim vermeniz gerekmektedir:
“Gazi_Insaat_CE102_Final_ÖğrenciAdı_ÖğrenciSoyadı_ÖğrenciNumarası”
Örneğin  “Gazi_Insaat_CE102_Final_Sergen_Yalçın_181130093”
5. Dosyalarınızın açılabilir olup olmadığını gönderme aşamasında kontrol ediniz! Bazı
öğrencilerin, kasıtlı şekilde bozuk veya kırık dosya atma eğilimleri olabiliyor. Bu öğrenciler, ders
sorumlularıyla görüşerek dosyanın bozuk veya kırık olması nedeniyle ödevlerini sonraki bir tarihte
tekrar gönderip değerlendirilmesini talep ediyorlar. Bu tarz bir olaya kesinlikle izin
verilmeyecektir. Dosyalarınızı göndermeden önce açılıp açılmadığını mutlaka kontrol ediniz (örn.
önce kendinize e-posta atıp başka bir cihazda açmayı deneyebilirsiniz).
6. Kopyanın veya benzerliğin hiçbir türüne izin verilmeyecektir. En ufak bir benzerlik durumunda final
ödeviniz kopya muamelesi görecektir. Bu ödevler notlandırılmayacaktır. Dahası böyle bir hataya
düşen öğrenciler hakkında gerekli idari işlemler başlatılacaktır.
7. Bu final ödevi 4 sayfada yer alan 4 sorudan oluşmaktadır. Lütfen soruları dikkatlice okuyunuz.
Sorularda istenenleri atlamayınız. Bir çözümde belirli bir yöntemin kullanılması veya
kullanılmaması istenmişse buna mutlaka riayet ediniz. Aksi takdirde çözümleriniz doğru dahi olsa
puan alamayacaktır.
FINAL ASSIGNMENT QUESTIONS
Question 1 (25 points)
 Write a function called “minandmax”.
 Function “minandmax” takes only one input argument that is a matrix M.
This matrix M can be any size (any number of columns and rows) with any random integer values.
 Function “minandmax” returns two output arguments.
The first output argument is called difference_row that returns a row vector containing the absolute
values of the difference between the maximum and minimum valued elements in each row.
The second output argument is called difference_all that returns the difference between the maximum
and minimum valued elements in the entire matrix.

An example is given below:


>> M = randi (50, 3, 5)
M=
43 32 26 9 2
4 11 5 16 49
6 44 40 12 17
>> [difference_row, difference_all] = minandmax (M)
difference_row =
41 45 38
difference_all =
47

 Generate any random matrix of your choosing with sizes you want and integer values you want.
 Execute the described function on your matrix.

!! Please write the necessary function !!


!! Please show the matrix you selected and give the results of your function from this matrix !!

BE CAREFUL! Correct function declaration with the correct names for output arguments, input
argument, and function name is required!

DO NOT use if-statements, for loops or while loops in this answer. They will not be graded.
We expect you to use basic matrix/arithmetic operations and built-in functions (i.e. abs & max & min).
Question 2 (25 points)
The table below shows the income from sales of a construction company for each year.

INCOME FROM SALES FOR EACH YEAR

Year
2017 2018 2019
Company
Company A 200 250 400
Company B 50 650 150
Company C 550 300 Please select an income value you want

 Create a bar graph by executing your code.


 The title of the graph must be named “INCOME FROM SALES FOR EACH YEAR”.
 The x-axis must be years and the y-axis must show income values.
 There should be a legend that shows what each color represents.

An example bar graph generation is given below:


>> variable1 = [1 2 3 4 5];
>> variable2 = [4 70 39 45 68; 28 32 77 65 66; 5 96 80 71 17; 10 4 19 76 12; 83 44 49 28 50]
>> bar (variable1, variable2)

If you do not understand how to use bar graph from this example, please write “help bar” to your
Command Window to see how it works.

!! Please show every command (statement) you executed on the Command Window to generate the
bar graph with the required properties !!
!! Please attach the image of the bar graph !!
Question 3 (25 points)
 Write a function called “cold”.
 Function “cold” takes only one input argument called temperatures that is a vector of integers
corresponding to daily lowest temperatures in oC.
This vector can have any number of elements.
 Function “cold” returns only one output argument called number_of_cold_days that is the number
of days with freezing temperatures (lower than 0 oC).

An example is given below:


>> temperatures = [3, -2, -5, 22, 18, -12, 0];
>> number_of_cold_days = cold (temperatures)
number_of_cold_days =
3

 Generate any random temperature vector of your choosing with the length and values you want.
 Execute the described function on your vector.

!! Please write the necessary function !!


!! Please show the vector you selected and give the results of your function from this vector !!

BE CAREFUL! Correct function declaration with the correct names for output argument, input
argument, and function name is required!

We expect you to use LOGICAL INDEXING in this solution. Other solutions will not be graded.
Question 4 (25 points)
A factorial is the product of all the integers from 1 to N.
However, 0! (0 factorial) is a special term and the result is equal to 1.
Then, 1! (1 factorial) is equal to 1*1 = 1.
Then, 2! (2 factorial) is equal to 1*2 = 2.
Then, 3! (3 factorial) is equal to 1*2*3 = 6.
Then, 4! (4 factorial) is equal to 1*2*3*4 = 24.
Then, 5! (5 factorial) is equal to 1*2*3*4*5 = 120.

 Write a function called “fact” that calculates the factorial of any non-negative integer.
 Function “fact” takes only one input argument called x that is a non-negative integer.
 Function “fact” returns only one output argument called result that is equal to x! (x factorial).

 Prepare your function for scalar and non-negative integer values.


If the user enters non-scalar values, negative values, or non-integer values, the function should send
the necessary error messages to the user for input correction (robustness).
 If the user enters more than one input argument, MATLAB automatically warns the user with an
error message saying, “too many input arguments”.
However, it does not send any error messages when the user does not enter any inputs. So, in case the
user does not enter any inputs, please send an error message for user to enter an input value.

!! Please write the necessary function !!


!! Please show the results by calling your function form the Command Window as follows:
>> result = fact (0)
>> result = fact (5)
>> result = fact (any positive integer you select)
>> result = fact ( )
>> result = fact (-2)
>> result = fact (6.6)

BE CAREFUL! Correct function declaration with the correct names for output argument, input
argument, and function name is required!

You can use any method you want. However, you cannot use the built-in function factorial that is
already available in MATLAB.

You might also like