Thread: Jumping Into C++: Chapter 14 Problem 1

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    1

    Jumping Into C++: Chapter 14 Problem 1

    Hello,

    Just curious as to whether or not I've implemented this code correctly.

    Code:
    // Rafael Negron
    // 7.20.2014
    /* Write a function that builds a two-dimensional multiplication table with arbitrary sizes for the two dimensions. */
    
    #include <iostream>
    
    using namespace std;
    
    void multiplication_table(int size)
    {
        int **p_p_table;
        p_p_table = new int*[size];
    
        for (int i = 0; i < size; i++)
        {
            p_p_table[i] = new int[size];
        }
    
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                p_p_table[i][j] = i * size;
            }
        }
    
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                cout << "[ " << i << " ] [ " << j << " ] = ";
                cout << p_p_table[i][j];
                cout << "\n";
            }
        }
    
        for (int i = 0; i < size; i++)
        {
            delete[] p_p_table[i];
        }
        delete[] p_p_table;
    }
    
    int main()
    {
        int size;
    
        cout << "Enter: ";
        cin >> size;
    
        multiplication_table(size);
    
        cin.ignore();
        cin.get();
    }
    Thank You

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I see that the practice problem is stated very open-ended as: "Write a function that builds the multiplication table of arbitrary dimensions". Remember to state this in the future since not everyone here has a copy of the book.

    Quote Originally Posted by programmerafael
    Just curious as to whether or not I've implemented this code correctly.
    Have you compiled and run your program with various input to test it?

    I would expect you to have three functions: one function to create the multiplication table of the given size and populate it, another function to print it, and yet another function to destroy it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    looking at line 23 I see that whole line receives same value - does not looks like any multiplication table I have seen
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Jumping Into C++ Chapter 14 Practice Problem 1
    By ArtemisFowl2nd in forum C++ Programming
    Replies: 5
    Last Post: 04-16-2014, 09:36 PM
  2. jumping into c++ chapter 5 problem 7
    By etricity in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2014, 11:23 PM
  3. Jumping Into C++ - Chapter 8 Problem[3]
    By Mohamed Adel in forum C++ Programming
    Replies: 3
    Last Post: 08-28-2013, 09:14 AM
  4. Jumping To C++ - Chapter 8 Problem
    By Mohamed Adel in forum C++ Programming
    Replies: 4
    Last Post: 08-27-2013, 01:02 PM
  5. Jumping into C++ Chapter 5 problem 6 - Critique please
    By Kranky in forum C++ Programming
    Replies: 8
    Last Post: 03-07-2012, 05:44 PM