Once this form has been customized for your institution, you can use this button to send your lab work. Be sure to read the instructions
before starting your work.
To gain experience with
Write a program that creates a vector ringof pointers toCircle objects, that is, a vector<Circle*>
ring;. Your job is to fill rings with five pointers to circles that are configured like the interlocking
Initialize the vector by allocating five circles on the heap with new and calling push_back
to append the resulting pointers to the vector.
Write a loop that displays all elements in rings on the graphics screen
Write a loop that deletes all heap objects whose pointers are stored in rings
Combine the code into a main program that prints out the Olympic rings.
/* paste program here */
Note: In this example, there was no advantage to using a vector<Circle*>. It would have been
easier to use a vector<Circle>. The purpose of this exercise was to get you used to the pointer
notation and dynamic allocation.
This is a worthwhile exercise since the next lab (on inheritance) uses a vector<Card*> to hold
a vector of cards (such as an ID card, a phone card, and so on). In that lab, it is essential that you use a vector
of pointers--a vector<Card> will not be sufficient.
The following program contains several errors in the way that the pointers are dereferenced. Please correct
the program and paste your corrected version in the textarea below.
using namespace std;
Student(string student_name, string major_at_acceptance);
void set_major(string new_major);
string get_major() const;
string get_name() const;
name = "";
major = "";
Student::Student(string student_name, string major_at_acceptance)
void Student::set_major(string new_major)
major = new_major;
string Student::get_major() const
string Student::get_name() const
Student* trans_student = new Student("James Smith","Computer Science");
Student* new_student = new Student();
cout << (*new_student).get_major() <<"\n";
cout <<"Name: " <<new_student.get_name() <<"\n";
Student next_student = new Student();
if (next_student->get_major() == "Computer Engineering")
cout <<"Another computer engineer!\n";
/* paste program here */
Create a class called Student_Club, which will store information on student clubs. The Student_Club class should
have as fields President, Vice-President, Secretary, Treasurer, all of which should be pointers to a student object.
In this way, a student could hold offices in many different clubs and we would not have to keep separate information
about that student in each instance of Student_Club. Your class definition should also include constructors as
well as accessor functions.
Rewrite the following program to use pointers instead of arrays:
cout <<"Enter Salary: ";
Using the Student_Club class created in P3, add one additional field, members, which should be an array of pointers
to student objects.
Write a function Count_Cut(char x) that accepts a character string as input, counts the number of characters
and returns the left half.
Look at the following examples and write your answer in the column next to the example.