Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Intermediate C++
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share
Lecture Comments (7)

1 answer

Last reply by: Alvin Sylvain
Mon Nov 4, 2013 7:41 AM

Post by Karen Brown on November 3, 2013

Okay, there is a function called "add" and a class called "option", and we have to pass a constructor into it. It looks like this:
c->add(new option("sure",5));
I am confused on how to write the function "add". I have never had to pass a constructor before. I do not know how to write the parameters or anything.

2 answers

Last reply by: Karen Brown
Sun Nov 3, 2013 6:55 PM

Post by Karen Brown on November 3, 2013

OK...there is this one function that is like a double function, and I keep getting memory leaks
Question?? How do I pass a new choice class constructor that takes 2 arguments to a function?

1 answer

Last reply by: Alvin Sylvain
Wed Sep 25, 2013 5:49 AM

Post by Karen Brown on September 24, 2013

Hello Professor Sylvain,
Here is an assignment that I received from my college computer class.
I did not understand any of this, nor did the students that I was collaborating with.
Assignment Description:
You will be creating a class that models the mathematics construct of a Matrix. A Matrix is a 2-dimensional structure, you will model this with 2d dynamic array. Your matrix will be able to add itself to another Matrix object and a couple other operations.

class Matrix : public LoggableIfc
     Matrix(int rows = 0, int cols = 0);
     Matrix(const Matrix& m);
     Matrix operator=(Matrix);
     int* operator[](int);
     //Addition functions
     Matrix add(const Matrix &m) const;
     Matrix operator+(const Matrix& m) const;
     static int getMatrixCount();
      int rows;
      int cols;    
      int **data;    
      static int matrixCount;

int Matrix::matrixCount = 0;

Function Description
int* operator[](int n);
Overloaded square brackets '[]' for Matrix class,
returns the nth integer pointer column
Matrix operator+(const Matrix& m) const;
return the sum of two matrices
static int getMatrixCount();
return the value of matrixCount

matrix input file (a, b, c, d)
You will need to read in 4 matrices from a file. You need to check the upload site for the exact names, but generically, they are named as follows:


Each input file will be of the form....: rows
0,0 0,1 0,2...
1,0 1,1 1,2...

Example: 3
34 23 23 65
45 234 42 64
324 34 654 21

Driver (Showoff)
This is a mandatory file in which I expect you to show off your new class. You will want to test things like: •A+B

Testing Files
Testing each class you create is mandatory and must have 3 tests for each function in the class. You do not have to test the destructor.


Overview of Intermediate C++

    I expect that you should be able to accomplish these tasks without much difficulty. If you have problems with these, consider taking the introductory class first.

    • Create a program that announces “Good Morning, Planet Earth!” to the user
    • Modify the program to read a file named “planet.txt”. The content of the file should be the name of the planet, so that the program will announce, “Good Morning, Planet {name of planet from the file}
    • Add an array of structures, where each structure contains the name of a planet, and how far away from the Sun it is (you’ll have to look up that information). When the program reads the name of the planet in the file, find that planet in the array of structures, and print how far away that planet is from the Sun. Print a suitable message if the planet is not found.
    • Add a function that, given the planet as a parameter, returns the difference between that planet’s distance and Earth’s distance. Call that function to print out that difference.
    • If the distance is zero (Earth), print a message, “Welcome home!”
    • Modify your program so that “Planet” is an object class instead of a structure. Include attributes such as, name of planet, distance from the sun, mass, gravity at its surface, and anything else you think might be interesting for the exercise.
      • Add “getters” for each attribute, but not “setters”. The attributes should not be changed once they’re set (at least I don’t suppose Mars is getting closer, is it?)
      • Add methods to read the attributes from a file.
      • Add methods to print out the attributes in some friendly format (e.g., “The mass of this planet is {insert mass here}”)
      • Add a method to return the difference between the distance from the Sun of this planet and the distance to Earth.
      • Write a test program to run your object class through its paces.

Overview of Intermediate C++

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  1. Intro
    • Overview
      • Review
      • Containers; Vector
      • Containers; List
      • Containers; Set, Map
      • Templates
      • Object Oriented Programming
      • Operator Overloading
      • Exception
      • Exception Handling in C++
      • Namespaces
      • Input/Output
      • More Details for Functions
      • More Kinds of Types
      • Pre-Compiler Macros
      • Compiling the Code
      • Tally Ho!
        • Intro 0:00
        • Overview 0:22
        • Review 3:10
          • Language Features You're Expected to Already be Familiar With
          • Introduce New Features and Cover Some Familiar Territory More In-Depth
        • Containers; Vector 4:45
          • Features: Templates and Containers
          • Vector is the First Container Learned
          • Example
        • Containers; List 7:18
          • Linked List is One of the Most Basic Data Structures in Computer Science
          • This Class Shows How to Use the Standard Library 'List' Container
          • Example
        • Containers; Set, Map 9:15
          • Binary Tree
          • 'Set' and 'Map' are Not Sequential
          • Set Retrieves Unique Keys
          • Map Retrieves a Unique Key, Then the Related Value
          • Example
        • Templates 12:00
          • Allow for Code Re-Use and Modularity
          • Example
        • Object Oriented Programming 15:19
          • OOP is the Main Motivating Factor to the Original Development
          • Only Grafted on Non-OOP Features
          • Discuss How Classes and Objects Are Created and Instantiated in C++
        • Operator Overloading 18:29
          • Writing Polymorphic Functions
          • Operator Overloading is a Standard Feature in Most Programming Language
          • Example
        • Exception 21:05
          • Practical Programming Means Handling Unexpected Conditions in an Expected Way
          • Programmers Have Used Different Techniques to Pass Along Info That's 'Less Than Good'
        • Exception Handling in C++ 23:51
          • C++ Exceptions Can be Any Type
          • Example
        • Namespaces 25:30
          • Name Collision
          • C++ Solution is for Each Company to Use Their Own Unique Namespace
          • Example
        • Input/Output 27:43
          • Class Hierarchy for C++ Input/Output
          • Turn on Exception Handling and Check Input/Output Status Bits
          • How to Use 'Stringstream' Object
        • More Details for Functions 29:19
          • Parameters on the Main Function
          • Inline Functions
          • Recursive Functions
          • Pass Pointers to Functions as Function Parameters
        • More Kinds of Types 32:23
          • Union to Force Memory Overlap
          • Enum Type
          • Typedef Keyword
          • Keeping Things the Same 'Const'
        • Pre-Compiler Macros 34:09
          • '#include'
          • '#define'
          • Conditional Compilation with '#ifdef'
        • Compiling the Code 35:57
          • Dash D Testing
          • Common Flags
          • Flag That Allows a Run-Time Debugger to Hook Into the Application
        • Tally Ho! 39:07