Homework 01
CSC 3320 – System-level Programming
Due Date: Wednesday, June 25 t h at midnight
Please read all the instructions. Your regex solutions and program should be typed up. We will not
accept handwritten or photocopied submissions. Include all required files in your submission on
iCollege. You can submit a single zip file or upload separate files.
You will have to answer several questions about pattern matching using regular expressions. For your
reference, a regular expression cheat sheet has been copied for you below.
Description
Meta Characters Description
Asterisk ( * ) 0 or more
Plus ( + ) 1 or more
Curly Braces { } N,
min or more,
min to max
Wildcard ( . ) Matches anything
Optional ( ? ) Preceding character is
optional
Group ( ) Group together multiple
characters
Characte
r Classes
\s Whitespace (space & tab)
\S Non-whitespace
\d Digits
\w Words (alpha-numeric)
\W Non-words (punctuation & whitespace)
\b Word Boundary
Q1 – Write a regex that can match a phone number in the following format:
(###) ###-####
^\(\d{3}\)\s\d{3}-\d{4}$
Q2 – Write a regex that can detect words spelt in both American English and British English.
A) Words that end in ze (American English) and se (British English). Write a regex that can
match both spellings of Familiarize and Familiarise.
Familiari(s|z)e
B) Words that are spelled with an o in British English and American English. Write a regex that
can match both spellings of Color and Colour.
Colou?r
Q3 – Write a regex that can match with valid IPv4 addresses. The typical format of an IPv4 address is
A.B.C.D where A, B, C, and D are Integers lying between 0 and 255 (both inclusive). Ex. 108.177.122.102
\b(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3} (?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\b
Q4 – Write a regex that can match with a URL. The regular expression must be able to match a url with
and without the https:// prefix. Ex. www.youtube.com & https://www.youtube.com
^(https:\/\/)?(www\.)?[a-zA-Z0-9\-]+(\.[a-zA-Z]{2,})(\/[^\s]*)?$
Program: Passenger Management System Lite
For this homework assignment, you will implement the initial data entry functionality of an airline
passenger management system. You will write a C program to read in information about a passenger and
their flight information. Your program will utilize String Functions previously discussed in class to create a
welcome message for the user, including their flight information.
Program Requirements
All variables must be of type char[].
Use macro directives to declare constants for all string lengths.
# define NAME_LEN x
…
void main(void) {
char first_name[NAME_LEN];
Prompt the user with a suitable message to read their first name, last name, airline, flight
number, seat row number, and seat letter
Enter the passenger’s first name:
Enter the passenger’s last name:
Enter the airline name:
Enter the flight number:
Enter the seat row number:
Enter the seat letter:
Read the input of each prompt using scanf() into their own variables, respectively, with
meaningful names.
o Implement scanf() safely to prevent the user from exceeding the maximum string
length.
Create a welcome message by combining user input with string literals using the string functions
strcpy() and strcat().
o Utilize the “safer” strncpy() and strncat() so that the maximum length of the
string cannot be exceeded.
Display a welcome message in the following format using printf():
Welcome [First] [Last]! Your flight is [Airline] [Flight Number].
Your seat is [Seat Row][Seat Letter].
You are not required to use Snowball to write this program. However, your program will be
graded based on whether it works correctly on Snowball, so you should ensure it compiles and
runs on Snowball.
Example Output
Important
Your coding style is just as important as the correctness of your program. Unlike your programs in the
lab, you will be evaluated on your variable names and use of comments in addition to the program
output. Your code must include a block comment at the top of your C file with your name and a
description of your program. Your variable names should be meaningful and descriptive of their
contents.
Deliverables
Please upload the C program code for your passenger management system, along with its output, to the
terminal on iCollege. Please name your C code and screenshot using the following format:
C Files
o lastname_firstname_filename.c
o For example, hawamdeh_faris_passenger.c
Screenshots
o lastname_firstname_filename.png
o For example, hawamdeh_faris_passenger.png