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

CS100 Computational Problem Solving

Fall 2021-22 (Section L3)

Deadline: 10:55AM Monday 6th December 2021

PreLab12: Pointers & Dynamic Memory


Total Marks = 20
Welcome to the Last Pre-Lab
Lab Guidelines

1. You must put all your work into a folder named PreLab10_YourRollNo_TA (e.g,
PreLab11_22100103_Zeeshan), compress it into a “zip” file and submit the zip
file on LMS (Assignment -> PreLab11) before Monday, 29th November
10:55AM. No late submissions or email submissions will be accepted.
2. Communicating with each other is NOT permitted. Searching for answers or help on the
internet is not permitted. All help material provided in the Lab Manual is allowed. If you
have a question, ask the TAs on Slack in your lab section channel.
3. The object is not simply to get the job done, but to get it done in the way that is asked for
in the lab. The objective is not just to get the code working, but to have a deep
understanding of why it is working. The viva will judge you on that.
4. Any cheating case will be reported to the Disciplinary Committee without any delay.
5. Failure to adhere to the naming convention of the file will result in 2.5 marks deduction.
6. Failure to adhere to coding conventions of the file will also result in 2.5 marks deduction.

Coding Conventions:
● Constants are “ALLCAPS” or “ALL_CAPS”.
● Variables are “allsmall” or “all_small”.
● All function names must be “firstWordSmallAllOtherWordsCamelCase”.
● All curly brackets defining a block must be vertically aligned.
● File naming: Lab09_YourRollNo_TA

Learning Objective:
• Learn the use of pointers and dereferencing.
• Getting accustomed to dynamic memory
Task [20 marks]
Your job is to create a journal app that allows the user to save short journals about their feelings, day
after day.
Your program continues to run as long as the user wants to keep adding entries to the journal.
Save the entries to an array.

The program starts by asking the user to choose one of the following options:
1. Add a new entry to journal
2. View previous entries
3. Close program

You store the user’s entries in an array (1D array). Each index of the array is an entry. When the
program starts, the array has size 0, meaning it is just a pointer pointing to NULL. Then, when the
user wishes to add a new entry, you dynamically allocate memory and the array’s size is now 1. You
ask the user what the entry is, and store the entry to the array. Make sure to use getline, not cin.

Then the menu is displayed again. If the user wants to add another new entry, the array’s size is now
increased to 2 by dynamically allocating more memory. The new entry is stored at the next index.

The user can view all entries at any time or close the program.

Bonus
You get +10 marks if you save these entries to a txt file every time a new entry is added, and load the
entries from the text file every time the program is restarted, so that even if the program is closed, the
user’s journals are not lost. Total lab marks will not exceed 100.

You might also like