0% found this document useful (0 votes)
6 views

Assignment 4: CS 115 001 - Object-Oriented Design Due: April 8, 2024

Uploaded by

imaanjot20
Copyright
© © All Rights Reserved
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)
6 views

Assignment 4: CS 115 001 - Object-Oriented Design Due: April 8, 2024

Uploaded by

imaanjot20
Copyright
© © All Rights Reserved
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/ 4

Assignment 4

CS 115 001 - Object-Oriented Design


Due: April 8, 2024

Instructions:
Your program should be written in C++. Please submit the source files for both exercises.

Marking Scheme:
1. Readability and programming style (10%): The program should be easy to read, well commented, structured
(i.e. should incorporate proper layout, indentation, white-spaces, etc.), and well designed (i.e. should follow
top-down design approach). Follow the commenting guidelines for interface specification provided in the
class/slides/notes.
2. Compiling and execution process (10%): The program must compile and execute without errors and warnings.
3. Correctness (80%): The program should produce correct results.

4. Sample-based marking might be practised for this assignment.

Questions:
1. Write a program that prompts the user to input a string and outputs the same string but in upper-case. If
a character in the string is not a lower-case letter, the output should be the same character, i.e. no changes
happen for characters that are not lower-case. You must use a dynamic character array to store the string.
Sample input/output:
Enter a s t r i n g : s t g d i f g d %0d 3 f
The upper c a s e s t r i n g i s : STGDIFGD%0D3F
Enter a s t r i n g : abCDe892
The upper c a s e s t r i n g i s : ABCDE892

2. Implement a linked list of integer numbers. The first node of the linked list is pointed by the pointer ptr.
You can consider that each node is of the following type:
s t r u c t Node{
i n t Item ;
Node ∗ Next ;
};

By considering that the first node of the linked list is pointed by ptr, implement the following functions:

1
• bool IsEmpty(Node *ptr): This function returns true if the linked list is empty, and false otherwise.
• int GetLength(Node *ptr): This function returns the number of elements in the linked list.
• Node *FindItem(Node *ptr, int ItemToFind): This function returns the pointer of the first node
that contains the item ItemToFind. If the item does not exist, the function returns a null pointer.
• void InsertItem(Node *ptr, int NewItem): This function adds the NewItem to the linked list. The
item must be inserted in a sorted (ascending) order.
• void DeleteItem(Node *ptr, int ItemToDelete): This function deletes the first node of the linked
list that contains the item ItemToDelete. If the item does not exists, nothing happens.
• void Print(Note *ptr): This function prints all the elements in the linked list.

Write a main function that tests all these functions. In your main function, please closely follow the sample
input/output shown below.
Sample input/output:

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 1
The l i s t i s empty !

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 4
Enter t h e number : 3
Thanks , i n s e r t e d 3 i n t h e l i s t .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 4
Enter t h e number : 1

2
Thanks , i n s e r t e d 1 i n t h e l i s t .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 4
Enter t h e number : 3
Thanks , i n s e r t e d 3 i n t h e l i s t .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 4
Enter t h e number : 100
Thanks , i n s e r t e d 100 i n t h e l i s t .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 6
Here you go : 1 3 3 1 0 0 .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 5
Enter t h e number : 3
Thanks , d e l e t e d 3 from t h e l i s t .

Choose an o p t i o n :

3
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 3
Enter t h e number : 3
Found i t !

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 3
Enter t h e number : 9
That number i s not i n t h e l i s t .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 6
Here you go : 1 3 1 0 0 .

Choose an o p t i o n :
0 to quit .
1 t o know whether t h e l i s t i s empty .
2 t o know t h e number o f e l e m e n t s i n t h e l i s t .
3 t o f i n d an item i n t h e l i s t .
4 t o i n s e r t a n o t h e r item i n t h e l i s t .
5 t o d e l e t e an item from t h e l i s t .
Finally , 6 to p r i n t a l l the items . 0
Ciao !

You might also like