Skip to content

I am sharing the answers to the homework assignments of my EEF110 Intr course at ITU.

Notifications You must be signed in to change notification settings

TolgaKilinckaya/EEF110-Introduction-to-Programming-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EEF110-Introduction-to-Programming-C

I am sharing the answers to the homework assignments of my EEF110-Introduction to Programming(C) course at ITU.

Homework 1

Description

  1. Plot a sine wave using according to the given height and width variables.
  2. Find the shortest distance from a given point to a segment whose endpoints are known.

Output

Screenshot 2023-04-04 150034 Screenshot 2023-04-04 151201


Homework 2

Description

A static memory is given in order to optimize the memory usage of the code. The static memory needs to be used for multiple complex numbers.
• Use a #define statement named MAX for the amount of storable complex numbers.
float mem[] represents the static memory.
int count represents the number count.
Implement the following functions,
void print(): prints the whole memory to the console in 1 + 1i format.
void print_polar(): prints the whole memory to the console in 1.414214[+45.000001deg] format.
void push(float re,float im): adds a complex number to the memory if capacity not full.
void pop(): removes the last added complex number from the memory and places zeros.
void sort(): sorts the complex numbers in ascending order in both real and imaginary values.
void sort_polar(): sorts the complex numbers in ascending order in both magnitude and phase
values.

Output

image


Homework 3

Description

  1. A data type called Node is used to encapsulate data and to implement the data type Stack. Stack is used with a Last-In-First-Out data exchange strategy. This data type is going to be implemented like the Linked-List. Implement the following functions,
    void print(Stack* s): prints the stack (only for debug purposes).
    void push(Stack* s,int val): adds the new value to the stack.
    int pop(Stack* s): removes the last added value from the stack.

  2. The data type created in the previous question called Stack is going to be used to develop an interpreter. This interpreter uses a special syntax where if two numbers are given consecutively they are pushed into the stack, if an operator is detected then two numbers are popped from the stack, the operator is applied to the numbers and the result is pushed back into the stack. Using this, it is possible to implement a mathematical interpreter.
    int str2num(char* str): a helper function which converts an entire string into an integer.
    int interpret(Stack* s,const char* str): uses the provided stack and the string, interprets the string’s mathematical syntax content and returns the appropriate result as an integer.
    Only integers are used and all operations are integer operations. Only +,−, ∗ and / are supported.

Output

Screenshot 2023-06-17 204138


Quiz 3

Description

A code that generates smooth curves is going to be implemented. Implement the functions given in the template,
void CreateScreen(char**,int,int): is responsible to generate a screen array of characters.
void DestroyScreen(char*): frees the memory allocated.
void PrintScreen(char*,int,int): as the name implies prints the char array to the screen.
void MixCoordinates(float (*)[2],float[2],float[2],float): blends two 2d-vectors into one by using v3 = (1 − t)v1 + tv2, where 0 ≤ t ≤ 1.
void GenerateCurve(char**,int,int,float[2],float[2],float[2],float[2]: uses 4 points to generate the curve. It mixes the 2d-vectors like

a=mix p_0 and p_1
b=mix p_1 and p_2
c=mix p_2 and p_3
d=mix a and b
e=mix b and c

where 0 ≤ t ≤ 1. And places a ’+’ character on the character array to be printed on the screen. Place also ’x’ characters for the points p0, p1, p2 and p3.

Output

image image

About

I am sharing the answers to the homework assignments of my EEF110 Intr course at ITU.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published