Showing posts with label chapter 15 drills. Show all posts
Showing posts with label chapter 15 drills. Show all posts

Saturday, 15 August 2020

Chapter 15 // Class Definition Drills 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the header file std_lib_facilities found here:
https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

Chapter 15 // Class Definition Drills

9. Change the representation of Person to have first_name and second_name instead of name. Make it an error not to supply both a first and a second name. Be sure to fix >> and << also. Test.

Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2015/Class%20Definition%20Drills/Drill%209

.

Friday, 14 August 2020

Chapter 15 // Class Definition Drills 8 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the header file std_lib_facilities found here:
https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

Chapter 15 // Class Definition Drills

8. Read a sequence of Persons from input (cin) into a vector<Person>; write them out again to the screen (cout). Test with correct and erroneous input.

Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2015/Class%20Definition%20Drills/Drill%208

.

Thursday, 13 August 2020

Chapter 15 // Class Definition Drills 1, 2, 3, 4, 5, 6, 7 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the header file std_lib_facilities found here:
https://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

Chapter 15 // Class Definition Drills

1. Define a struct Person containing a string name and an int age.
2. Define a variable of type Person , initialise it with "Goofy" and 63, and write it to the screen (cout).
3. Define an input (>>) and an output (<<) operator for Person; read in a Person from the keyboard (cin) and write it out to the screen (cout).
4. Give Person a constructor initialising name and age.
5. Make the representation of Person private, and provide const member functions name() and age() to read the name and age.
6. Modify >> and << to work with the redefined Person.
7. Modify the constructor to check that age is [0:150] and that name doesn't contain any of the characters ; : " ' [] * & ^ % $ # @ ! . Use error()  in case of error. Test.

Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2015/Class%20Definition%20Drills/Drills1-7

Wednesday, 12 August 2020

Chapter 15 // Shape Function Graphing Drills 1, 2, 3, 4, 5, 6, 7, 8, 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the graphics files found here:
https://github.com/l-paz91/principles-practice/tree/master/Graphics%20Files

Chapter 15 // Function Graphing Drills

1. Graph the function  double one(double x) {return 1;} in the range [-10,11] with (0,0) at (300,300) using 400 points and no scaling (in the window).
2. Change it to use x scale 20 and y scale 20.
3. From now on use that range, scale, etc. for all graphs.
4. Add double slope(double x) {return x/2;} to the window.
5. Label the slope with a Text "x/2" at a point just above its bottom left end point.
6. Add double square(double x) {return x*x;} to the window.
7. Add a cosine to the window (don't write a new function).
8. Make the cosine blue.
9. Write a function sloping_cos() that adds a cosine to slope() (as defined above) and add it to the window.

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2015/Function%20Graphing%20Drills%202


All of these functions can be found from section 15.2 to 15.3.2. If you have already followed along with the chapter you will have done them.

Drill 2-1:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-2:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-3, 2-4:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-5:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-6:
It annoys me that this one doesn't scale
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-7, 2-8:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Drill 2-9:
Chapter 15 //  Shape Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

Friday, 7 August 2020

Chapter 15 // Function Graphing Drills 1, 2, 3, 4, 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the graphics files found here:
https://github.com/l-paz91/principles-practice/tree/master/Graphics%20Files

Chapter 15 // Function Graphing Drills

1. Make an empty 600-by-600 Window labeled "Function Graphs".
2. Note that you'll need to make a project with the properties specified in the "installation of FLTK" note from the course website.
3. You'll need to move Graph.cpp and Window.cpp into your project.
4. Add an x axis and a y axis each of length 400, labeled "1 == 20 pixels" and with a notch ever 20 pixels. The axes should cross at (300,300).
5. Make both axes red.

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2015/Function%20Graphing%20Drills


I am lazy and I've been using the same project since the start of Chapter 12.