Csc 1302, Honors Principles of Computer Science II (Fall 2023)

Week 1 (25 August 2023)

Database, Relation, Tuple

Sample Database Instance

Database Class: Encapsulates the entire database, which is nothing but a collection of relations (or tables). We shall use a dictionary to store the relations with relation name serving as the key and the Relation object as the value.

class Database:

	def __init__(self):
		self.relations = {}

Relation Class: Encapsulates a relation or table; includes both schema and instance.

class Relation:

	def __init__(self,name,attributes,domains):
		self.name = name.upper() # name of relation
		self.attributes = [a.upper() for a in attributes] # list of names of attributes
		self.domains = [d.upper() for d in domains] # list of "INTEGER", "DECIMAL", "VARCHAR"
		self.table = [] # list of tuple objects

Tuple Class: Encapsulates a tuple or row of a relation; includes both schema and instance.

class Tuple:
	def __init__(self,attributes,domains):
		self.attributes = [a.upper() for a in attributes]
		self.domains = [d.upper() for d in domains]
		self.tuple = []

TO DO

Download the Skeleton files and implement all the methods in these Python classes. Compile and run the driver program. You should see the following output:

mirage:week1 raj$ python3 Driver.py 
Database Schema: 

STUDENT(SID:INTEGER,SNAME:VARCHAR,MAJOR:VARCHAR,GPA:DECIMAL)
COURSE(CNUM:VARCHAR,CTITLE:VARCHAR,DESCRIPTION:VARCHAR,CREDITS:INTEGER)

Relation r1: 
STUDENT(SID:INTEGER,SNAME:VARCHAR,MAJOR:VARCHAR,GPA:DECIMAL)
Number of tuples:2

1111:Robert Adams:Computer Science:4.0:
1112:Charles Bailey:Mathematics:3.0:

Relation r2: 
COURSE(CNUM:VARCHAR,CTITLE:VARCHAR,DESCRIPTION:VARCHAR,CREDITS:INTEGER)
Number of tuples:2

CSC 1301:Intro to CS I:Java Programming and breadth topics:4:
CSC 1302:Intro to CS II:In depth Java Programming and some breadth topics:4: