CS246 Study Guide - Midterm Guide: Glossary Of Video Game Terms, C String Handling, Linked List

90 views8 pages
Published on 16 Oct 2011
School
University of Waterloo
Department
Computer Science
Course
CS246
Professor
CS 246 Midterm Review
Sean Hsueh
Winter 2009, Updated: February 23, 2009
1. Considering the following code and its output. Draw out the state of the memory at the specified location. Write out
the output of stderr.
#include <iostream>
#include <string.h>
using namespace std;
char vowels[] = ”aeiou”;
void mystery ( const charptr )
{
const chartmp = ptr;
cout << ”&ptr: ” << &ptr << endl;
cout << ”ptr: ” << (void) ptr << endl;
cout << ”&tmp: ” << &tmp << endl;
for ( ; tmp; tmp++ )
{
cerr << ”tmp: ” << (void) tmp << endl;
cerr << tmp << endl;
}
// RIGHT HERE
}
int main ()
{
char mystring [ 10 ];
strcpy ( mystring, ”test );
int size = strlen ( mystring );
cout << ”&vowels: ” << &vowels << endl;
cout << ”&mystring: ” << &mystring << endl;
cout << ”&size: ” << &size << endl;
mystery ( vowels );
};
Stdout
------------------------------------------------------------------
&vowels: 0x804a040
&mystring: 0xbf8fedd6
&size: 0xbf8fedd0
&ptr: 0xbf8fedb0
&tmp: 0xbf8feda0
1
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in
2. Consider the following code. What is the output of the program?
Listing 1: out1.h
cout << ”264” << endl;
Listing 2: out2.h
cout << ”1351” << endl;
Listing 3: out3.h
cout << ”454” << endl;
Listing 4: out4.h
cout << ”.” << endl;
Listing 5: prog.cpp
#include <iostream>
using namespace std;
int main ()
{
#include ”out3.h”
#include ”out4.h”
#include ”out1.h”
#include ”out2.h”
#include ”out4.h”
return 0;
}
2
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in
3. Write a stack for doubles using a linked list. The stack has the following interface. Do not use STL:
Listing 6: DoubleStack.h
class DoubleStack
{
private:
// Whatever is necessary..
public:
DoubleStack ();
void push ( double val );
double pop (); // assume pop is always called with at least 1 element in stack
double peek (); // assume peek is always called with at least 1 element in stack
bool isEmpty ();
˜DoubleStack ();
};
3
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Winter 2009, updated: february 23, 2009: considering the following code and its output. Draw out the state of the memory at the speci ed location. What is the output of the program? cout << 264 << endl; cout << 1351 << endl; cout << 454 << endl; cout << . << endl; #include using namespace std; int main () 2: write a stack for doubles using a linked list. Doublestack (); void push ( double val ); // assume pop is always called with at least 1 element in stack double pop (); double peek (); // assume peek is always called with at least 1 element in stack bool isempty (); 3: write a program that compares two les and output the line numbers as well as its content where they di er. If a le is shorter than the other, then the last comparable line is the number of lines in the shorter le.