Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-13-2005, 01:20 AM   #1 (permalink)
bradleyc
Registered User
 
Join Date: Aug 2005
Posts: 17
bradleyc is on a distinguished road
On right track?

Quote:
a. Create a class named Matrix2x2 having four floating point data members named n1, n2, n3, n4. The class's default constructor should provide data members with default values of 1 if no explicit user initialization is provided. Additionally, provide member functions for displaying an object's data values and for calculating the determinant (see below). Also provide the class with an overloaded operator function that is capa¬ble of multiplying two Matrix2x2 objects according to the following procedure:
example of Matrix2x2 : | n1 n2 |
| n3 n4 |

multiplication:
|n1 n2| |N1 N2| |n1N1 + n2N3 n1N2 + n2N4|
|n3 n4| x |N3 N4| = |n3N2 + n4N4 n3N2 + n4N4|

determinant of |n1 n2| = n1n4 – n3n2
|n3 n4|
b. Include the class in a working C++ program that tests each of the class's member functions.
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>


class Matrix2x2
{
private:
float n1;
float n2;
float n3;
float n4;

public:
Matrix2x2(int = 1. int = 1, int = 1, int =1);
void calcDet();
Matrix2x2 operator*();

};

Matrix2x2::Matrix2x2(int nOne, int nTwo, int nThree, int nFour)
{
 n1 = nOne;
 n2 = nTwo;
 n3 = nThree;
 n4 = nFour;
}

void Matrix2x2::calcDet()
{



}

Matrix2x2 Matrix2x2::operator*()
{


}
bradleyc is offline   Reply With Quote
Old 10-13-2005, 04:35 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Quote:
Code:
#include <stdlib.h>
Waba.... where in this piece of code does it require the stdlib header ??
Quote:
Code:
#include <conio.h>
Given that this is just a simple implementation I would suggest to use the math header instead, atleast it is system independant, and later on we might end up doing some serius mathmatical equations where it might come in handy.
Quote:
Code:
Matrix2x2(int = 1. int = 1, int = 1, int =1);
That is just plain wrong
You can't create a function like that..
Code:
Matrix2x2(float nOne=1.0, float nTwo=1.0, float nThree=1.0, float nFour=1.0);
might be a better aproach, firstof you're private variables are floats, if you're gonna assign int values to them, why the hell declare them as floats in the first place??
Quote:
Code:
void calcDet();
You might want this to return a float, given that the determinant often reveals a value...
Quote:
Code:
Matrix2x2 operator*();
This could be returning Matrix2x2& if I'm not mistaken.

And the calculations for determinant and multiplications are strait out of the box, it's math 101. May I suggest Linear Algebra - Gateway to methmatics by Robert Messer, isbn: 0-06-501728-5 as a good reference.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-13-2005, 10:42 AM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
... and "we" don't like conio's in this part of the forum as well... .
__________________
Valmont is offline   Reply With Quote
Old 10-13-2005, 01:43 PM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Hey Val, haven't seen you in a while..
Are you getting settled in ?
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Fractal Terrain Generation Algorithm brad_galloway Standard C, C++ 5 04-17-2005 07:48 PM
Rip entire CD as 1 track!? Admin Linux / BSD / OS X 8 12-05-2004 03:04 PM


All times are GMT -8. The time now is 08:27 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting