sysc 2006 foundations of imperative programming assignment 02 table of
Search for question
Question
SYSC 2006: Foundations of Imperative Programming
Assignment 02
Table of Contents
Objectives........
............
Text-based Facebook
The Problem..........
..........
Designed Solution……………………………..
Choice 1: Register a new user ……………………………….
Choice 2: Manage a user's profile: .
Choice 3: Manage a user's posts: .
Choice 4: Manage a user's friends: ..
.............
Choice 5: Display all posts from a given user: ............
Choice 6: Exit the application:
Sample Output.......
................
Implementation Requirements........
Wrap UP & Submission.........
Carleton Department of Systems
and Computer Engineering
University
1
1
2
3
3
4
4
6
8
8
9
11
......
12
....
Objectives
Practice and test your understanding of the following imperative programming concepts using C as
programming language:
Structures
Memory Allocation
• Linked lists and its operations
Text-based Facebook
Facebook is a social media platform that allows users to connect with friends by creating profiles,
sharing posts, photos, and videos, and engaging in various online activities. With over billions of
active users, Facebook is one of the most prominent and influential social networking platforms
globally.
Although Facebook has a user interface (website) to allow users to use its functionalities, the user
interface is often used to take user input, then pass it to several functions that run in the background
Page 1 of 12 Carleton Department of Systems
and Computer Engineering
SYSC 2006: Foundations of Imperative Programming
University
(on the server), then display (return) results back to the user interface. Without these functions, you
cannot implement such an interactive web application.
In this assignment, you will implement some functions that could go behind the user interface.
The Problem
You decide to test your gained knowledge from the course to implement a text-based version of
Facebook. The application should have these functionalities:
1. Registering new users (username, userid, and password).
2. Allowing users to manage their profile (Change their password).
3. Display/Add/Remove friends from the user profile.
4. Add/Remove posts from the user profile.
5. Display all posts from a given users.
For each user, you need to store:
-
Username
User id
Password
List of friends (sorted as a linked list in ascending order by user id)
Posts (designed as a stack)
Figure 1, shows the design of the "database" and how all components are connected.
Hermione
Ron
202
Username: HarryPotter
105
next
NULL
Userid: 101
next
Password: abasb
friends
posts
next
NULL
Username: Voldemort
NULL
NULL
Userid: 105
Password: abasb
Avada Kedavra
end
friends
posts
next
next
next
Ron
Draco
105
109
NULL
next
next
Username: Hermione
Userid: 202
Password: abasb
friends
posts
next
NULL
Figure 1 Database design
Accio!
NULL
next
Figure 1 explanation:
•
Users (black boxes) are stored in a sorted linked list in ascending order by user id.
Friends of a user (red boxes) are stored in a sorted linked list in ascending order by user
id.
•
Posts of a user (blue boxes) are stored as a stack.
Page 2 of 12 Carleton Department of Systems
and Computer Engineering
University
SYSC 2006: Foundations of Imperative Programming
Designed Solution
You consulted with your course instructor and friends, and you have decided to design the
application as follows.
The landing text of the application is the MAIN MENU, which will prompt the user to choose an
option.
***********************************************
MAIN MENU:
***********************************************
1. Register a new User
2. Manage a user's profile (change password)
3. Manage a user's posts (add/remove)
4. Manage a user's friends (display/add/remove)
5. Display a user's posts
6. Exit
Enter your choice:
Figure 2 Main menu
Note: The user has to enter a valid value, if the user enters an invalid input, ask them to
enter another value.
***********************************************
MAIN MENU:
***********************************************
1. Register a new User
2. Manage a user's profile (change password)
3. Manage a user's posts (add/remove)
4. Manage a user's friends (display/add/remove)
5. Display a user's posts
6. Exit
Enter your choice 7
Invalid choice. Please try again.
Figure 3 Wrong main menu choice
-
Choice 1: Register a new user
"
When the user chooses option 1, they should be prompted with the option to enter a new
user's username, user's id and password.
■
Your code should call add_user() function to add a user to the database.
■
Note: the new user should be added in the right location of an ascending ordered linked
list of users.
Note: you do not need to check if the user is already on the list. Just add it to the right
location.
Page 3 of 12 SYSC 2006: Foundations of Imperative Programming
Carleton Department of Systems
University
and Computer Engineering
Enter your choice: 1
Enter a username: Dumbledore
Enter a userid: 1010
Enter an upto 15 characters password Gryffindor
**** User Added!
****
Figure 4-Adding new user successfully
■
Once it is finished, the application will return to the main menu.
Choice 2: Manage a user's profile:
■
When the user chooses option 2, they should be prompted with the option to enter a
username that you want to change their password.
O If the username is found in the users list, then they will be prompted with the option
to enter a new password.
○
Enter your choice: 2
Enter username to update their password: Dumbledore
Enter a new password that is upto 15 characters: Lord Voldemort
**** Password changed! ****
Figure 5 - Changing a user's password
If the username is not found in the users list, then an error will be shown.
Enter your choice: 2
Enter username to update their password: Harry Potter
User not found.
Figure 6 - Invalid user when changing password
Once it is finished, successfully or with an error, the application will return to the main menu.
Choice 3: Manage a user's posts:
○
When the user chooses option 3, they should be prompted with the option to enter a
username that you want to manage their posts.
If the username is found in the users list, the application should show all the user's posts.
Then they will be prompted with a list with 3 options to choose from: add a post, remove
a post, or return to the main menu.
If there are no posts for that user (users's posts linked list is empty), the application should
also display a message "No posts available for XXXXX.", where XXXXX is the user's name
as shown in the sample run below.
Page 4 of 12 SYSC 2006: Foundations of Imperative Programming
Carleton Department of Systems
University
and Computer Engineering
о
Enter your choice: 3
Enter username to manage their posts: Dumbledore
Dumbledore's posts
No posts available for Dumbledore.
1. Add a new user post
2. Remove a users post
3. Return to main menu
Your choice:
Figure 7 - Manage user's posts menu
If the username is not found in the users list, then an error will be shown, and the
application will return to the main menu.
Enter your choice: 3
Enter username to manage their posts: Harry Potter
User not found.
Figure 8- Invalid username when trying to update posts
Add post (Choice 1)
○ When the user chooses to add a new user's post (Choice 1), they will be prompted with
the option enter a post under 250 characters. After the user enters a post, the list of posts
should be updated using add_post() function, the lists of posts the user has will be
displayed, and the post menu will be displayed again.
Your choice: 1
Enter your post content: What happened down in the dungeons between you and Prof
essor Quirrell is a complete secret... so, naturally the whole school knows
Post added to your profile.
Dumbledore's posts
1- Dumbledore: What happened down in the dungeons between you and Professor Quir
rell is a complete secret... so, naturally the whole school knows
1. Add a new user post
2. Remove a users post
3. Return to main menu
Your choice:
Figure 9 - Adding a new post
NOTE: Usually reading user input into a string using scanf(), we use %s format
specifier. However, this only works if the string has no spaces (one word). Since the
post is a sentence, we must use a special format specifier [^\n]s". This format
Page 5 of 12/n/nStarting code
1. Download the zipped file that corresponds to
your operating system.
2. Extract (unzip) the zipped file.
3. Open the extracted folder and double-click on
"A02.code-workspace". This should open the
workspace in VS Code.
4. Start solving the assignment.
NOTE: The starting code will not compile until you
implement a version of the adduser(), addfriend(), and
addpost() functions. You are given a
"read_CSV_and_create_users" function that calls the
above mentioned functions./n Implementation Requirements
•
•
•
Depending on your operating system, download (A02_Windows.zip or A02_macOS.zip) the
starting code from Brightspace and extract the zipped file.
NOTE: The starting code will not compile until you implement a version of the adduser(),
addfriend() and addpost() functions. You are given a "read_CSV_and_create_users” function
that calls the above mentioned functions.
Open VS Code by double clicking on “A02.code-workspace” file. Alternatively, you can open
VS Code then choose "File -> Open Workspace from File".
A02_xxx folder contains the following files:
a2_nodes.h
and posts.
-
defines the data structures you must use to create lists of users, friends
a2_functions.h - contains the declarations of the functions you must implement. The
function prototypes and names must be used exactly as in the provided file. All these
functions must be used in your solution.
IMPORTANT: You are allowed to create extra functions as long as they complement the required
ones and do not replace them. New function declarations must go inside a2_functions.h
о
al_functions.c - contains the definitions (implementations) of the functions listed in
al_functions.h.
main.c contains the main function of your program. There shouldn't be any functions
declared or defined in this file other than main() function.
Your solution should go in the provided four files. You are not allowed to create extra files.
Page 11 of 12 Carleton Department of Systems
University
and Computer Engineering
•
SYSC 2006: Foundations of Imperative Programming
Enter your information at the top of each provided file in the assigned location.
You are not allowed to modify any of the functions' declarations/prototypes. The code you are
not allowed to modify is highlighted with “/********** DON'T MODIFY ********** /”.
• You have to write the program in C language (not C++) using Visual Studio Code. Do not use
any C++ elements. Examples of C++ elements:
#include <iostream>
○
○
using namespace std;
•
•
•
•
○
...
Global variables are forbidden.
Your constants must be defined using the #define preprocessor directive.
Your .h files must include header guards.
You have to properly assign data types based on what is needed (for example, you should use
unsigned short int if your variable's maximum value is 1000 and minimum is O)
You should add comments to your code where needed.
Do not use anything that we have not discussed up to this point in the material. You are only
allowed to use what you learned from Lecture 1 to Lecture 20.
• Similar ideas might be available online. If you use any code available online, your
assignment will be sent to the Dean's office as a potential case of plagiarism. You must
work on your own, without the help of others, and you are not allowed to reuse any code
available online.
Wrap UP & Submission
○ Make sure that your solution adheres to the implementation requirements. If you fail to
follow the implementation requirements, you will lose marks or even receive a ZERO.
○
○
If your code does not compile, your grade will be ZERO. At this point in your degree,
you should be able to provide code that compiles. No exceptions, even if it is a small
typo.
If you make any changes to your code, recompile again before resubmitting to ensure there
are no compilation errors.
■
TAs will test your code by compiling your submitted solution using the following
statements (discussed in Lecture 5) in the terminal. Make sure to run these statements
and fix all problems and issues shown before you submit your solution to avoid receiving
a zero.
• Windows:
•
gcc -g .c -o A02_marking.exe
./A02_marking.exe
MacOS:
gcc -g .c -o A02_marking
./A02_marking
Submit "main.c", "a2_functions.c", "a2_functions.h" and "a2_nodes.h" on Brightspace
before the deadline.
No email submissions are allowed. You will receive a zero if you miss the deadline or submit
by email.
Page 12 of 12/nA02 - Clarification
☑
Cristina Ruiz Martin posted on Mar 25, 2024 11:56 AM
QUESTION:
I have a question for the
Bool
delete_post(user_t *user,
int
number)
function.
What does the "int number" mean. I'm assuming it's
the number of the post you want to remove, but in the
sample output, it removes the latest post. However,
let's say the number of the post is 7, how are you
supposed to know to input an int number 7 in the
parameter? I understand this is LIFO, but I don't know
how to implement it.
ANSWER:
Just ignore the parameter number in the
implementation, as we are following the LIFO
approach.
When you call the function, just provide a random
integer.
I kept that header with that parameter, as you will
need that input parameter in the bonus
assignment 2.