Vous êtes sur la page 1sur 18

< PROGRAM >

< SEMESTER / YEAR>

< COURSE CODE>

< COURSE TITLE>

MATRICULATION NO: <MATRIC NO>


IDENTITY CARD NO. : <IC NUMBER>
TELEPHONE NO. : <TELEPHONE>
E-MAIL : <EMAIL ID>
LEARNING CENTRE : <LEARNING CENTER>

0
INSTRUCTIONS
 Do not copy the assignment question and instructions to your answer.
 Prepare your assignment answer following the layout of the ASSESSMENT
CRITERIA shown in the RUBRICS provided for the course. Where RUBRICS are
not provided, follow the instructions/guidelines specified by the Open University
Malaysia (OUM) for the assignment concerned.
 Your assignment should be written according to the number of words outlined in
the assignment instruction EXCLUDING references.
 Type your answer using 12 point Times New Roman font and 1.5 line spacing.
 Show the number of words at the end of your assignment.
 Tables and figures where provided, should be appropriately titled.
 List your references separately in the APPENDIX page.

1
ATTACHMENT

QUESTION 1

You are given a table that shows the assignment and examination marks of CBDS 2103

students for the JANUARY 2019 semester.

No 1 2 3 4 5 6 7 8 9 10
Assignment Marks 88 75 92 35 67 77 56 95 63 35
Examination Marks 78 68 95 20 75 65 45 97 82 44

Based on the given information, you are required to do the following:

1. Create a 2-D array that will record the student’s assignment and examination marks.
2. Input the assignment and examination marks.
3. Calculate the average assignment and examination marks.
4. Calculate the total assignment and examination marks.
5. Display all of the calculated marks.

The assessment will be done based on the following criteria:

i. A proper writing of C codes and its structure


ii. The ability of program to be compiled and executed

iii. Implementation of correct programming techniques

iv. Complete documentation and correct submission

Note: You must write C programming codes for this assignment.

2
ANSWER:

/*

LINKED LIST IMPLEMENTATION BY C PROGRAMMING LANGUAGE

OPERATION: CREATE A 2-D ARRAY THAT WILL RECORD THE STUDENT’S ASSIGNMENT

AND EXAMINATION MARKS

PROGRAMMED BY: MUHD.ZAKI ZULFADLI BIN ABDUL HAJIS

STUDENT ID:880301526953001

CONTACT:+60 19-842 0340

*/

#INCLUDE <IOSTREAM>

USING NAMESPACE STD;

INT MAIN()

INT ROWS; //ASSIGNMENT MARKS

INT COLUMNS = 2; //EXAMINATION MARKS

DOUBLE AVERAGE = 0;

COUT<< "HOW MANY ASSIGNMENT SCORE DO YOU WANT TO INPUT" << ENDL;

CIN >> ROWS;

DOUBLE** SCORES_ARRAY = NEW DOUBLE*[ROWS];

FOR(INT I = 0; I < ROWS; I++)

SCORES_ARRAY[I] = NEW DOUBLE[COLUMNS];

SCORES_ARRAY[I][1] = I+1;

3
COUT <<" ENTER ASSIGNMENT SCORE " << I+1 << ":";

CIN >> SCORES_ARRAY[I][0];

AVERAGE = AVERAGE + SCORES_ARRAY[I][0];

AVERAGE = AVERAGE / ROWS;

FOR(INT I = 0; I < ROWS; I++)

COUT << SCORES_ARRAY[I][1] <<" YOUR RESULT SCORE #" ;

COUT << SCORES_ARRAY[I][0] << ENDL;

COUT <<"YOUR AVERAGE MARKS IS: " << AVERAGE;

RETURN 0;

4
OUTPUT:

Second step is choose the assignment score than I choose 5 assignment that it will ask to

key in the marks for assignment 1 until 5 than it will calculate the average all the

assignment marks.

5
QUESTION 2

In computing, the process identifier (normally referred to as the process ID or PID), is a


number used by most operating system kernels, to uniquely identify an active process. The
PIDs are usually allocated on a sequential basis, beginning with 0 and rising to a maximum
value that varies from system to system. Create a link list to store the PIDs. To create a new
PID, createPID() function is used. Each PID is inserted into the list at the beginning of the list,
using insertPID() function. Once a process is completed, that particular PID is deleted, using
the deletePID() function.

The assessment will be done based on the following criteria:

i. A proper writing of C codes and its structure

ii. The ability of program to be compiled and executed

iii. Implementation of correct programming techniques

iv. Complete documentation and correct submission

Note: You must write C programming codes for this assignment

6
ANSWER :-

/*

LINKED LIST IMPLEMENTATION BY C PROGRAMMING LANGUAGE

CODE COURSE:CBDS 2103

COURSE:DATA STRUCTURE

OPERATION :CREATE LIST, INSERT ITEM TO LAST, INSERT ITEM TO FIRST,

INSERT ITEM TO MIDDLE, SEARCH AN ITEM, DELETE AN ITEM, PRINT LIST

PROGRAMMED BY: MUHD.ZAKI ZULFADLI BIN ABDUL HAJIS

STUDENT ID:880301526953001

CONTACT:+60 19-842 0340

*/

#INCLUDE <STDIO.H>

#INCLUDE <MALLOC.H>

#INCLUDE <STDLIB.H>

7
STRUCT NODE {

INT VALUE;

STRUCT NODE *NEXT;

};

VOID INSERT();

VOID DISPLAY();

VOID DEL();

INT COUNT();

TYPEDEF STRUCT NODE DATA_NODE;

DATA_NODE *HEAD_NODE, *FIRST_NODE, *TEMP_NODE = 0, *PREV_NODE, NEXT_NODE;

INT DATA;

INT MAIN() {

INT OPTION = 0;

PRINTF("SINGLY LINKED LIST EXAMPLE - ALL OPERATIONS\N");

WHILE (OPTION < 5) {

PRINTF("\NOPTIONS\N");

PRINTF("1 : INSERT INTO LINKED LIST \N");

PRINTF("2 : DELETE FROM LINKED LIST \N");

PRINTF("3 : DISPLAY LINKED LIST\N");

PRINTF("4 : COUNT LINKED LIST\N");

8
PRINTF("OTHERS : EXIT()\N");

PRINTF("ENTER YOUR OPTION:");

SCANF("%D", &OPTION);

SWITCH (OPTION) {

CASE 1:

INSERT();

BREAK;

CASE 2:

DEL();

BREAK;

CASE 3:

DISPLAY();

BREAK;

CASE 4:

COUNT();

BREAK;

DEFAULT:

BREAK;

RETURN 0;

//THE PROGR

VOID INSERT() {

PRINTF("\NENTER ELEMENT FOR INSERT LINKED LIST : \N");

SCANF("%D", &DATA);

9
TEMP_NODE = (DATA_NODE *) MALLOC(SIZEOF (DATA_NODE));

TEMP_NODE->VALUE = DATA;

IF (FIRST_NODE == 0) {

FIRST_NODE = TEMP_NODE;

} ELSE {

HEAD_NODE->NEXT = TEMP_NODE;

TEMP_NODE->NEXT = 0;

HEAD_NODE = TEMP_NODE;

FFLUSH(STDIN);

VOID DEL() {

INT COUNTVALUE, POS, I = 0;

COUNTVALUE = COUNT();

TEMP_NODE = FIRST_NODE;

PRINTF("\NDISPLAY LINKED LIST : \N");

PRINTF("\NENTER POSITION FOR DELETE ELEMENT : \N");

SCANF("%D", &POS);

IF (POS > 0 && POS <= COUNTVALUE) {

IF (POS == 1) {

TEMP_NODE = TEMP_NODE -> NEXT;

FIRST_NODE = TEMP_NODE;

PRINTF("\NDELETED SUCCESSFULLY \N\N");

10
} ELSE {

WHILE (TEMP_NODE != 0) {

IF (I == (POS - 1)) {

PREV_NODE->NEXT = TEMP_NODE->NEXT;

IF(I == (COUNTVALUE - 1))

HEAD_NODE = PREV_NODE;

PRINTF("\NDELETED SUCCESSFULLY \N\N");

BREAK;

} ELSE {

I++;

PREV_NODE = TEMP_NODE;

TEMP_NODE = TEMP_NODE -> NEXT;

} ELSE

PRINTF("\NINVALID POSITION \N\N");

VOID DISPLAY() {

INT COUNT = 0;

TEMP_NODE = FIRST_NODE;

PRINTF("\NDISPLAY LINKED LIST : \N");

WHILE (TEMP_NODE != 0) {

PRINTF("# %D # ", TEMP_NODE->VALUE);

COUNT++;

TEMP_NODE = TEMP_NODE -> NEXT;

11
}

PRINTF("\NNO OF ITEMS IN LINKED LIST : %D\N", COUNT);

INT COUNT() {

INT COUNT = 0;

TEMP_NODE = FIRST_NODE;

WHILE (TEMP_NODE != 0) {

COUNT++;

TEMP_NODE = TEMP_NODE -> NEXT;

PRINTF("\NNO OF ITEMS IN LINKED LIST : %D\N", COUNT);

RETURN COUNT;

OUTPUT:-

WHEN RUN THIS PROGRAM IT WILL POP LIKE THIS

Second step is when we choose option 1,for the option is to insert the linked list then

enter the element so I enter 100.

12
Third step is I choose to display the linked list which that I already insert the value which

is 100 so it display the value 100

13
Fourth is I choose option 2 which is to the delete the linked list so it will pop up the

command which enter position for delete the element.the delete is successfully.

14
Fifth step is I choose the number 4 option to count the linked list than it will display
display the no of item in linked list

15
16
Lastly is exit program,when I enter number 5 the program will terminate and exit cause
number 5 is not in the option.

17

Vous aimerez peut-être aussi