print out to a printer, need help

This is a discussion on print out to a printer, need help within the C++ Programming forums, part of the General Programming Boards category; So i'm done with the homework, except for a piece that will optionally print out to a printer. Now unfortunately, ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    13

    print out to a printer, need help

    So i'm done with the homework, except for a piece that will optionally print out to a printer. Now unfortunately, I was late for that lecture. Is the professor literally asking the C++ program to print out, as if from a phyiscal printer? (Printing the output on a piece of paper?) If so, how would I go on to do so? It says exactly "The program will optionally print a printer"

    I do have the rest of the homework done, fyi

    Code:
    #include <iostream>
    #include "headertime.h"
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        char chrAnswer;
        MultiplyMatrices clsMatrix;
        
        cout << "The Matrices are setup as follows:" << endl << endl;
        cout << " __            __     __             __ " << endl;
        cout << "|   x1  x2  x3   |   |   y1  y2  y3    |" << endl;
        cout << "|   x4  x5  x6   |   |   y4  y5  y6    |" << endl;
        cout << "|   x7  x8  x9   |   |   y7  y8  y9    |" << endl;
        cout << " __            __     __             __ " << endl  << endl << endl;
        
        do
        {
            clsMatrix.voidfuncRequestMatrices();
            clsMatrix.voidfuncMultiplyMatrices();
            clsMatrix.voidfuncOutput();
            cout << "If you'd like to use the program again, enter a 'y'";
            cin >> chrAnswer;
        }
        
        while (chrAnswer == 'y');
    
        system ("PAUSE");
        
    
    
        return 0;
    }
    Code:
    #ifndef headertime_H
    #define headertime_H
    
    #include <iostream>
    using namespace std;
    
    class MultiplyMatrices
    {
    	public: 
            int intMatrix1[3][3];
            int intMatrix2[3][3];
            int intMatrix3[3][3];
    		void voidfuncRequestMatrices();
    		void voidfuncOutput();
    		void voidfuncMultiplyMatrices();
    		
    
    
    
    };
    
    void MultiplyMatrices::voidfuncRequestMatrices()
    {
        cout << "Please enter the numbers for x1, x2, x3, and so on, until x9 for the first Matrix: ";
        cout << endl;
    
        for (int i = 0; i < 3; i++)
        {
            for (int y = 0; y < 3; y ++)
            {
                cin >> intMatrix1[i][y];
            }
            
        }
        cout << endl;
        
        cout << "Now enter numbers for the second Matrix in the same fashion they were entered for the first Matrix" << endl;
        
        for (int i = 0; i < 3; i++)
        {
            for (int y = 0; y < 3; y ++)
            {
                cin >> intMatrix2[i][y];
            }
            
        }
        
        cout << endl;    
    }
    
    void MultiplyMatrices::voidfuncMultiplyMatrices()
    {
           for (int i = 0; i < 3; i++)
           {
               for (int j = 0; j < 3; j++)
               {
                   int temp = 0;   
                   for (int k = 0; k < 3; k++)
                   {
                       temp += intMatrix1[i][k] * intMatrix2[k][j];
                       intMatrix3[i][j] = temp;
                   }
               }
           } 
    
    }
    
    void MultiplyMatrices::voidfuncOutput()
    {
        cout << "Here is the product of the two matrices:" << endl << endl;
        cout << " __            __ " << endl;
        cout << "|   " << intMatrix3[0][0] << "   " << intMatrix3[0][1] << "  " << intMatrix3[0][2] << "   |" << endl;
        cout << "|   " << intMatrix3[1][0] << "   " << intMatrix3[1][1] << "  " << intMatrix3[1][2] << "   |" << endl;
        cout << "|   " << intMatrix3[2][0] << "   " << intMatrix3[2][1] << "  " << intMatrix3[2][2] << "   |" << endl;
        cout << " __            __ " << endl  << endl << endl;
    }
    
    
    
    #endif

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    void foo ( ostream &where ) {
        where << "hello world\n";
    }
    
    int main ( ) {
        foo(cout);
        ofstream x("foo.txt");
        foo(x);
        return 0;
    }
    If you modify the output function to take a reference to a stream, then you can send the output wherever you want.
    The actual name of your printer device varies from OS to compiler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set Printer Prior To Loading Print Dialog Box
    By Beaner in forum Windows Programming
    Replies: 3
    Last Post: 10-10-2008, 02:02 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 09:13 PM
  4. send data to printer and print on paper
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 07-22-2002, 06:19 AM
  5. How to print to printer
    By zigona in forum C++ Programming
    Replies: 5
    Last Post: 11-16-2001, 03:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21