Homework 35: Linked list in C++
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Friday, April 21
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw35and submit using the204subcommand. - This is a written homework - be sure to turn in a hard-copy
of your completed assignment before the deadline. Use the
codeprintcommand to print out your code and turn that in as well.
Assignment
-
Circle one to indicate how you did for the reading assignment from
Homework 33 before class on Monday:
How carefully did you complete the reading? (Circle one)
Not at allSkimmed itRead someRead all -
Circle one to indicate how you did for the reading assignment from
Homework 34 before class on Wednesday:
How carefully did you complete the reading? (Circle one)
Not at allSkimmed itRead someRead all - Required reading for this homework:
Section 5 (structs and classes)
from the Unit 10 notes.
Circle below to indicate how you did for this reading assignment:How carefully did you complete the reading? (Circle one)
Not at allSkimmed itRead someRead all - Given the following C++ declarations:
fill in the following table with the type (only) of each expression. Write ERROR for if the expression would be a compiler or run-time error.void wombat(int x, double y); int wombat(int x); int wombat(char* s); int a; double b; char c; char d[128];expression type (or ERROR) awombat(a)wombat(a,b)wombat(b)a < bwombat(d) == 10wombat(a,b) == 10wombat(wombat(&c)) -
Note: This is the exact same assignment as from
Homework 32 from last week, except that now you
need to do it in C++, using
newanddeletefor example.Pierce the Painter likes to paint many layers of colors on top of each other, then strip them off and remember what was underneath. Write a program
paint.cppto help Pierce keep track of these colors.
Your program will read a series of two kinds of commands:paint color
Adds a layer of color on top of the current color.strip
Removes the topmost layer of color, revealing whatever was just underneath.
When Pierce tries tostripfrom a blank canvas, quit the program.Of course, you will want to create a linked list to help you! Each node in your linked list should store a single string, for the name of a color. When Pierce
paints, that means adding to the front of the linked list. When Pierce wants tostrip, that means removing the first node in the list.Examples
roche@ubuntu$./paintroche@ubuntu$./paintThe canvas is blank.striproche@ubuntu$./paintThe canvas is blank.paint redThe top color is red.stripThe canvas is blank.striproche@ubuntu$./paintThe canvas is blank.paint blueThe top color is blue.paint blueThe top color is blue.paint greenThe top color is green.stripThe top color is blue.paint orangeThe top color is orange.stripThe top color is blue.stripThe top color is blue.paint purpleThe top color is purple.paint purpleThe top color is purple.stripThe top color is purple.stripThe top color is blue.stripThe canvas is blank.paint whiteThe top color is white.stripThe canvas is blank.strip