



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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Exam; Professor: Sloan; Class: Data Structures; Subject: Computer Science; University: Wofford College; Term: Spring 2010;
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!
int main ( void ) { int *a, *b, x, y; x = 1; y = 2; a = &x; b = &y; *a = 3; *b = 4; cout << "Part a: " << x << y << endl; a = b; *b = 5; cout << "Part b: " << x << y << endl; a = new int; *a = 3; a = b; cout << "Part c: " << *a << *b << endl; delete a; }
#include "Widget.h" // include class definitions for widgets void foo(Widget &a) { cout << "Foo called" << endl; } void bar(Widget &b) { cout << "Bar called" << endl; } int main ( void ) { Widget c; Widget d(c); cout << "Main going strong" << endl; foo(c); bar(d); cout << "Main calling it quits" << endl; return 0; }
#include <iostream.h> class BallotBox { public: BallotBox(void); // initilizer void CastVote(int); // record votes void DisplayResults(void); // display election returns private: int democrat; int republican; }; BallotBox::BallotBox(void) { democrat = 0; republican = 0; } void BallotBox::CastVote(int vote) { if (vote) democrat++; else republican++; } void BallotBox::DisplayResults(void) { cout << "Democrats: " << democrat << endl; cout << "Republicans: " << republican << endl; } int main ( void ) { BallotBox election; election.CastVote(1); election.CastVote(1); election.CastVote(0); election.DisplayResults(); return 0; }