

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Class: DATA STRUCTURES; Subject: Computer Science - CSCI; University: Texas A & M University-Commerce; Term: Unknown 2005;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CSCI 270 Preliminary Quiz ( 7 Jun ) Name _________________________ Fall 2004
Given this partial class: class Course { public: int getCreditHours(); float getLabFee(); // other function prototypes will go here private: string dept; // department offering the course, like CSci int number; // course number, like 270 int creditHours; // # of credit hours a student earns, like 3 bool semOffered[8]; // semesters this course is usually offered where // subscript 1 = spring, 3 = summerI, 4 = summerII, 7 = fall float labFee; // amount charged for a lab fee, like 25. }
A constructor function always has the same name as the class:
Course(); // default constructor for this class Course(int number, int creditHours, float labFee);
Also constructors have no type. A constructor is neither a value-returning function nor a void function.
Yes, a client program may declare variables which have the same names as private variables in a class included by the program. Since the private variables are not directly accessible by the client program, there is no conflict. In fact, even if dept was a public variable of the Course class there would still be no conflict as class variables are part of and accessed through instances of the Course objects.
Course courses[10];
bool Course::isOffered(int semester) { return semOffered[semester]; }
or
bool Course::isOffered(int semester) { if (semOffered[subscript] == true) return true; else return false; }
if (c.isOffered(s)) cout << “YES” << endl; else cout << “NO” << endl;