• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Need C++ project ideas!

joomlads07

New Member
Joined
Feb 17, 2010
Messages
2 (0.00/day)
Location
3 Locust Street, Suite A Assonet, MA 02702
Linux system tools. I do a lot of these because you don't have to waste hours of your life writing a pretty user interface

The sorts of things I am doing lately are as follows...

* RPN math solver (command line math or read from file).
* Assembly Language interpreter (a proprietary conceptual demo).
* C/MySQL interface generator (builds corresponding DB tables and C structs based on lists).
 
Joined
Sep 10, 2008
Messages
532 (0.09/day)
Location
VA/PA
System Name Freyja
Processor Core i7 3770K
Motherboard AsRock Z77 Extreme4
Cooling Cooler Master Hyper 212 EVO
Memory 16 GB GSkill Sniper
Video Card(s) Diamond Radeon HD 7970
Storage Kingston HyperX 240 GB SSD + Seagate 2 TB HD
Display(s) Dell U2410
Case NZXT Tempest 210
Audio Device(s) Asus Xonar Essence STX
Power Supply Seasonic X-Series 750W
Software Ubuntu 13.04 64 bit
Have you picked a project, Mael? If so what are you working on?
Inquiring minds want to know !! lol

Oh crap, sorry, didn't realize people we're still responding to this thread, lol.

Project wise? Nothing. This semester has become much busier than I expected it to be (a ton of reading for multiple classes). So basically what I have been doing is reading the c++ tutorial on cplusplus.org (.com?) and then using all that I learn on making my c++ assignments waaaaaay overcomplicated :roll:. It's lots of fun, plus I am learning a good deal too. Once I have some time I'll sit down and work on some of the projects y'all suggested (spring break/summer). Damn college and its work, shouldn't it know by now that college is for fun and goofing off :p
 
Last edited:

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Good for you. Stick with it and all the hard work will pay off. :toast:
 

xbonez

New Member
Joined
Nov 29, 2010
Messages
1,182 (0.24/day)
Location
Philly, PA (US)
System Name Winter
Processor AMD Phenom II x4 965 BE @ 4.0Ghz
Motherboard MSI 790FX-GD70
Cooling Corsair H50 Liquid Cooling
Memory 2 x 2Gb Gskill Ripjaws 1600Mhz (7-7-7-24@1.6V)
Video Card(s) Asus GTX 470 @ Stock (Zalman VF3000 cooler)
Storage 2 x Samsung Spinpoint F3 500GB (RAID 0)
Display(s) Hanns G 28" @ 1920x1200
Case Antec 1200
Audio Device(s) Onboard -- TosLink --> Z5500
Power Supply Corsair 850TX 850W PSU
Software Win 7 64-bit Ultimate
While its extremely important to learn by reading concepts and stuff, one thing I have realized from personal experience is things don't persist in mind for long unless you actually utilize them. What I do, when learning a language is learn a concept (say dictionaries), then write a tiny program right away to use them. Keep building on this, so if the next concept u learn is serializing/deserializing XMLs, write a program that, say, deserializes an xml, adds the data to a dictionary.
 
Joined
Jun 24, 2008
Messages
1,365 (0.24/day)
Location
Alden, NY
System Name Turbo_Fighter/Pitbull
Processor AMD FX-9590/Intel i7 6700K 4.7GHZ @ 1.41 volts
Motherboard Gigabyte 990FXA-UD3 Rev 4.0/Gigabyte GA-Z170N-Gaming 5
Cooling Corsair H105/Corsair H100iv2
Memory 32 GB G.Skill Ares/32 GB G.Skill Trident-Z
Video Card(s) XFX Radeon R9 Fury X/Sapphire R9 Nano
Storage Mix of HDDs SSDs Externals and a 256GB Samsung M.2 in the pitbull
Display(s) 24" Nixeus 144hz freesync/24'' Benq XL2420TE/21.5'' Asus VH226/Panasonic 42" Plasma
Case White Phantom NZXT/Fractal Define Nano S
Audio Device(s) MayFlower O2 ODAC/HT Omega Claro+/Turtlebeach Earforce DSS
Power Supply Corsair AX1200i/Thermaltake Smart 650Watt(EVGA GS 650 Watt took a shit on me)
Mouse Logitech G502
Keyboard Corsair K70
Software Windows 10
Benchmark Scores They can run Crysis.
make a video game, about dolphins with flamethrowers
 
Joined
Feb 13, 2011
Messages
226 (0.05/day)
Location
AUSTIN,TEXAS
System Name ALIENWARE R8
Processor INTEL I5 9500 @3.9Ghz
Motherboard ALIENWARE 02XRCM
Cooling ALIENWAR Liqid Cooler
Memory DDR4 16GB @2.8Ghz
Video Card(s) NVIDIA GForce RTX 2070 8GB
Storage 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB
Display(s) VIZIO E-241 25" TV
Case ALIENWARE R8
Power Supply 850 WATTS
Mouse ROSWILL NEON M60
Keyboard ALIENWARE
Software WIN 10
I go through the same thing as the OP on what projects to undertake. But for me.. I do a sort of cost/time/usability analysis..As my time it worth something.. even to me.Kind of abstract concept and rarely is anything put to paper... Took me 6+ months to decide on my last project.. A board game to PC convert thats in VB and is like 5000 lines now.. not a small undertaking:banghead: Originally.. It was just to learn new ideas AND was never really meant to finish it.. 55% or so percent later.. LOL.. I think I will eventually finish it

When I was in school for Electronics, I wrote two programs.. One was for instantaneous voltage/current and the other was a very professional looking program for my physics teacher called Vector Summation..:nutkick:Granted.. all are written in Visual Basic 2007 but I could of done it in C++,Java, or C#..BUT VB is so much faster and VB is my love. I'm at the point now, it's what I call.. "Perpetual Learning"..

While its extremely important to learn by reading concepts and stuff, one thing I have realized from personal experience is things don't persist in mind for long unless you actually utilize them. What I do, when learning a language is learn a concept (say dictionaries), then write a tiny program right away to use them. Keep building on this, so if the next concept u learn is serializing/deserializing XMLs, write a program that, say, deserializes an xml, adds the data to a dictionary.

I do the same thing but I start out with a larger project that has alot of concepts in it

My next idea might be to scan my movies/music folder and catalog all items and export it to an excel file

@ the OP
Let us know what project idea you have decided on..To be honest.. I cant think of any projects for you.. Last project in C++ I did was to write the game farkle using GDI and to start on a black jack game done in console
 
Joined
Sep 10, 2008
Messages
532 (0.09/day)
Location
VA/PA
System Name Freyja
Processor Core i7 3770K
Motherboard AsRock Z77 Extreme4
Cooling Cooler Master Hyper 212 EVO
Memory 16 GB GSkill Sniper
Video Card(s) Diamond Radeon HD 7970
Storage Kingston HyperX 240 GB SSD + Seagate 2 TB HD
Display(s) Dell U2410
Case NZXT Tempest 210
Audio Device(s) Asus Xonar Essence STX
Power Supply Seasonic X-Series 750W
Software Ubuntu 13.04 64 bit
Spring break is getting closer (hellz ya!), just gotta get through 4 o'clock quizzes (think midterm, but instead of 2 exams per semester, its 3). Once that's done, its selling pc parts/c++ project time! Was thinking about going through this list I found of project ideas http://www.cplusplus.com/forum/beginner/3473/. # 25 on the list would be useful for my differential equations and linear algrebra class :toast: (though my calculator can already do them :laugh:)

Edit: Holy crap, got the best idea ever for my math class. Expand on matrix multiplication/addition and make it so the program can do E.R.O http://en.wikipedia.org/wiki/Elementary_row_operations. Oh ya, that's my next project, as that will be very helpful for my class!!
 
Joined
Feb 13, 2011
Messages
226 (0.05/day)
Location
AUSTIN,TEXAS
System Name ALIENWARE R8
Processor INTEL I5 9500 @3.9Ghz
Motherboard ALIENWARE 02XRCM
Cooling ALIENWAR Liqid Cooler
Memory DDR4 16GB @2.8Ghz
Video Card(s) NVIDIA GForce RTX 2070 8GB
Storage 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB
Display(s) VIZIO E-241 25" TV
Case ALIENWARE R8
Power Supply 850 WATTS
Mouse ROSWILL NEON M60
Keyboard ALIENWARE
Software WIN 10
After reading what I had wrote again

BUT VB is so much faster

VB is faster to develop BUT not in actual speed of execution ... Most new what I meant I feel but.......
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
A board game to PC convert thats in VB and is like 5000 lines now.. not a small undertaking

They asked me to write a database based ERP program at work. Last time I checked it was at about 50,000 lines of code. DOH !! lol

What keeps me interested in the project is that I know someone will use it and it is custom designed for them so they like it a lot. The downside is I'm the only coder and I have to generate all the reports (as well as manage the networks, computers, and be a DBA for two companies).

I guess I love being a geek. :laugh:
More beer please.

@Brandenburg : With the compile optimizations that occur, the .Net languages are all pretty close in execution speed.
 

PVTCaboose1337

Graphical Hacker
Joined
Feb 1, 2006
Messages
9,501 (1.43/day)
Location
Texas
System Name Whim
Processor Intel Core i5 2500k @ 4.4ghz
Motherboard Asus P8Z77-V LX
Cooling Cooler Master Hyper 212+
Memory 2 x 4GB G.Skill Ripjaws @ 1600mhz
Video Card(s) Gigabyte GTX 670 2gb
Storage Samsung 840 Pro 256gb, WD 2TB Black
Display(s) Shimian QH270 (1440p), Asus VE228 (1080p)
Case Cooler Master 430 Elite
Audio Device(s) Onboard > PA2V2 Amp > Senn 595's
Power Supply Corsair 750w
Software Windows 8.1 (Tweaked)

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
Heck yeah you count the "}" lines. Bragging rights you know. lol
 

xbonez

New Member
Joined
Nov 29, 2010
Messages
1,182 (0.24/day)
Location
Philly, PA (US)
System Name Winter
Processor AMD Phenom II x4 965 BE @ 4.0Ghz
Motherboard MSI 790FX-GD70
Cooling Corsair H50 Liquid Cooling
Memory 2 x 2Gb Gskill Ripjaws 1600Mhz (7-7-7-24@1.6V)
Video Card(s) Asus GTX 470 @ Stock (Zalman VF3000 cooler)
Storage 2 x Samsung Spinpoint F3 500GB (RAID 0)
Display(s) Hanns G 28" @ 1920x1200
Case Antec 1200
Audio Device(s) Onboard -- TosLink --> Z5500
Power Supply Corsair 850TX 850W PSU
Software Win 7 64-bit Ultimate
If you're counting physical lines, you count everything including {s. Some people prefer a count of logical lines, in which case the count is a lot lesser.
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
It really doesn't matter unless you are getting paid by lines of code.
I'm not, so for me it's just an eye opener to see how much work I've actually done.
Sort of a personal best kind of thing since I am not competing with anyone.

A little off topic, but it's interesting to examine projects from a dependancy view.
What I mean is that both W1zz's GPU-Z and my ERP program (although private) have outlived many multi-million dollar game budgeted productions.
People (whether many or a few) who depend on your work keep it alive and create a continual need for it to be robust and adaptive for a changing environment, which in turn requires you as a programmer to adapt to those needs in your code.
As a coder, there is no better feeling than when someone says, "It's just what I needed/wanted, well done."
 

PVTCaboose1337

Graphical Hacker
Joined
Feb 1, 2006
Messages
9,501 (1.43/day)
Location
Texas
System Name Whim
Processor Intel Core i5 2500k @ 4.4ghz
Motherboard Asus P8Z77-V LX
Cooling Cooler Master Hyper 212+
Memory 2 x 4GB G.Skill Ripjaws @ 1600mhz
Video Card(s) Gigabyte GTX 670 2gb
Storage Samsung 840 Pro 256gb, WD 2TB Black
Display(s) Shimian QH270 (1440p), Asus VE228 (1080p)
Case Cooler Master 430 Elite
Audio Device(s) Onboard > PA2V2 Amp > Senn 595's
Power Supply Corsair 750w
Software Windows 8.1 (Tweaked)
Because I went off topic I'll give you some ideas of what I did for fun:

-I made a RAR and JPG combiner, which would hide RAR's in JPG files. Worked faster than cmdprompt.

-I made a hidden RAR finder. I then tested it by lurking 4chan and downloading 1000 pictures. I found a WHOLE bunch of hidden RARs. And a whole bunch of porn inside them. '

-I made a program to put up a wall between the router and the internet. Pretty much it would redirect the router to thinking the internet was coming from an imaginary place. Therefore it would not work. I did this on my router, not the schools.

-I made a program in order to automatically broadcast the TPU recent posts to login window in Windows. This does still not work as it should.

Kinda fun to mess around with good and evil, as long as you have access to things to test on, with permission. Or just buy your own gear.

I also was messing with a little AI stuff, but I was unable to get too far with my limited understanding of structures of logic.
 
Joined
Feb 13, 2011
Messages
226 (0.05/day)
Location
AUSTIN,TEXAS
System Name ALIENWARE R8
Processor INTEL I5 9500 @3.9Ghz
Motherboard ALIENWARE 02XRCM
Cooling ALIENWAR Liqid Cooler
Memory DDR4 16GB @2.8Ghz
Video Card(s) NVIDIA GForce RTX 2070 8GB
Storage 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB
Display(s) VIZIO E-241 25" TV
Case ALIENWARE R8
Power Supply 850 WATTS
Mouse ROSWILL NEON M60
Keyboard ALIENWARE
Software WIN 10
Only mentioned the lines of code on my "small" project because its in VB which does a lot of things for you so theoretically it should be less lines. In my experience C++ takes a minimum of 4 times the amount of code to do a windows program than VB...i.e. Not Console.. In the game im writting.. I exclusively use classes,properties,enumerators and several functions that are reused 1000's of times.. In other words.. Its written very lean and IMO efficient... Its so well organized that once the groundwork was laid out.. everything just fell into place..To me.. Its a work of art in code..

Ill post some snapshots of it tomorrow in a new thread.. I'm sure some will laugh but it works and the forms are laid out pretty good.. Still haven't decided on a few things though...Its perhaps 50% done

here is a screenshot of a program I did for my physics instructor that earned me a +10 on a test.. Just did it because I was bored.. I showed it to him in a impromptu meeting.. and he loved it.. asked me to make a few changes.. mainly with the calculations of the 4th quadrant as in certain situations... it would calculate the wrong value


Next project will be an automatic catalog program for my movies/music on my PC..Never scanned folders before.. Will be very new to me

My suggestion to the OP is to make a "tool" that has a legitimate use for him...and sorry for mildly hijacking your thread
 
Joined
Sep 10, 2008
Messages
532 (0.09/day)
Location
VA/PA
System Name Freyja
Processor Core i7 3770K
Motherboard AsRock Z77 Extreme4
Cooling Cooler Master Hyper 212 EVO
Memory 16 GB GSkill Sniper
Video Card(s) Diamond Radeon HD 7970
Storage Kingston HyperX 240 GB SSD + Seagate 2 TB HD
Display(s) Dell U2410
Case NZXT Tempest 210
Audio Device(s) Asus Xonar Essence STX
Power Supply Seasonic X-Series 750W
Software Ubuntu 13.04 64 bit
It's all good. Started my E.R.O program, and its proving difficult to transform what I do when solving these problems (which is a lot of comparisons, multiplication, addition, and subtraction between the rows of matrices) into code. Granted, c++ probably isn't the best language to do what I'm doing, but I'm still going to go for it anyways xD
 

xbonez

New Member
Joined
Nov 29, 2010
Messages
1,182 (0.24/day)
Location
Philly, PA (US)
System Name Winter
Processor AMD Phenom II x4 965 BE @ 4.0Ghz
Motherboard MSI 790FX-GD70
Cooling Corsair H50 Liquid Cooling
Memory 2 x 2Gb Gskill Ripjaws 1600Mhz (7-7-7-24@1.6V)
Video Card(s) Asus GTX 470 @ Stock (Zalman VF3000 cooler)
Storage 2 x Samsung Spinpoint F3 500GB (RAID 0)
Display(s) Hanns G 28" @ 1920x1200
Case Antec 1200
Audio Device(s) Onboard -- TosLink --> Z5500
Power Supply Corsair 850TX 850W PSU
Software Win 7 64-bit Ultimate
After you're done with it, you could try porting it to a C# Winforms app so you can have a nice GUI too
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
If he's using Visual C++ he has access to all the same GUI classes as Visual C# does.
You get even more control if you write the GUI in WPF using XAML, but it's kind of a pain in the ass. Very powerful though.
 
Last edited:

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,049 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
If he's using Visual C he access to all the same GUI classes as Visual C# does.

not in "normal" unmanaged c++ using mfc
 

Kreij

Senior Monkey Moderator
Joined
Feb 6, 2007
Messages
13,817 (2.20/day)
Location
Cheeseland (Wisconsin, USA)
I haven't done much in C++ lately.
Visual C++ 2010 is still unmanaged code without Win32 wrappers and completely allows for unsafe code, no?
 
Joined
Sep 10, 2008
Messages
532 (0.09/day)
Location
VA/PA
System Name Freyja
Processor Core i7 3770K
Motherboard AsRock Z77 Extreme4
Cooling Cooler Master Hyper 212 EVO
Memory 16 GB GSkill Sniper
Video Card(s) Diamond Radeon HD 7970
Storage Kingston HyperX 240 GB SSD + Seagate 2 TB HD
Display(s) Dell U2410
Case NZXT Tempest 210
Audio Device(s) Asus Xonar Essence STX
Power Supply Seasonic X-Series 750W
Software Ubuntu 13.04 64 bit
It's all good. Started my E.R.O program, and its proving difficult to transform what I do when solving these problems (which is a lot of comparisons, multiplication, addition, and subtraction between the rows of matrices) into code. Granted, c++ probably isn't the best language to do what I'm doing, but I'm still going to go for it anyways xD

OK, so I just finished my E.R.O program. Just a little over 300 lines (I know that is nothing, but I'm still impressed by it :roll:). It can also add/subtract and multiple matrices! I had thought it would take me longer, oh well. Now, I gotta pick a new project :toast:.

Also, do you think I could post my code to have some of ya'll look at it? So ya'll can critique it, and such. Just as a reference point for what I know, I've read this tutorial up to pointers, have a little experience in Java from my AP comp sci class, and a little other c++ knowledge from googling.

Edit: realized a weakness in the code, need to fix it, but I'll go ahead and post it (dealing with division by zero for the E.R.O part).
 
Last edited:
Joined
Feb 13, 2011
Messages
226 (0.05/day)
Location
AUSTIN,TEXAS
System Name ALIENWARE R8
Processor INTEL I5 9500 @3.9Ghz
Motherboard ALIENWARE 02XRCM
Cooling ALIENWAR Liqid Cooler
Memory DDR4 16GB @2.8Ghz
Video Card(s) NVIDIA GForce RTX 2070 8GB
Storage 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB
Display(s) VIZIO E-241 25" TV
Case ALIENWARE R8
Power Supply 850 WATTS
Mouse ROSWILL NEON M60
Keyboard ALIENWARE
Software WIN 10
Joined
Sep 10, 2008
Messages
532 (0.09/day)
Location
VA/PA
System Name Freyja
Processor Core i7 3770K
Motherboard AsRock Z77 Extreme4
Cooling Cooler Master Hyper 212 EVO
Memory 16 GB GSkill Sniper
Video Card(s) Diamond Radeon HD 7970
Storage Kingston HyperX 240 GB SSD + Seagate 2 TB HD
Display(s) Dell U2410
Case NZXT Tempest 210
Audio Device(s) Asus Xonar Essence STX
Power Supply Seasonic X-Series 750W
Software Ubuntu 13.04 64 bit
Here it is, would probably be easier to read to just c-n-p it to a doc or something: Edit: Fixed the division by zero issue (i think), just had to add two if statements.
Code:
/*
 * File:   main.cpp
 * Author: Maelstrom
 *
 * Created on February 18, 2011, 2:25 PM
 */

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <vector>

/*
 * This program asks the user to enter a matrix, and then offers the user a number of operations the user can do to the matrix they
 * entered. The program starts off by having the user input the dimensions of the matrix. Then, it asks for each element of the matrix. Current
 * operations the user can can select are addition, subtraction, and multiplication.  E.R.O will be added in the future.
 */
void add(std::vector < std::vector <double> >, int, int); //will add two matrices, one of which is a parameter.
void e_r_o(std::vector < std::vector <double> >, int, int);
void multi(std::vector < std::vector <double> >, int, int); //will multiple two matrices, one of which is a parameter.
void print(std::vector < std::vector <double> >, int, int); //prints out the matrix.

int main() {
    std::cout << "Welcome to the Matrix manipulation program! This program can do a number of different mathmatical operations to matrices"
            " including Gaussian elimination. ";
    std::cout << "Please enter the dimensions and the elements of the matrix. Once completed"
            ", you will be given a number of mathmatical operations that can be applied to the matrix. "
            "Note: if you wish to find the solutions to a linear system, make sure to include what the equations are equal to." << '\n';
    int column, row; //for dimensions of the mxn matrix.
    std::string input; //used to store all input.
    while (true) { //infinite loop, will on be exited out of when user enters appropriate info.
        std::cout << "Enter the number of rows for the matrix: "; //asks for # of rows.
        std::getline(std::cin, input); //takes input as a string
        std::stringstream convert(input); //enters string into the stringstream.
        if (convert >> row) { //checks if the input can be converted into a double. If it can, it enters the number into row.
            if (row != 0) { //can't go having a matrix with 0 rows
                break; //exits out of loop.
            }
        }
        std::cout << "Error, please enter an appropriate number of rows." << '\n';
    }
    while (true) { //does the same as above, but for the number of columns.
        std::cout << "Enter the number of columns for the matrix: ";
        std::getline(std::cin, input);
        std::stringstream convert(input);
        if (convert >> column) {
            if (column != 0) {
                break;
            }
        }
        std::cout << "Error, please enter an appropriate number of columns." << '\n';
    }
    std::vector <std::vector <double> > matrix; //creates a multidimensional vector. Used instead of an array for ease of parameterizing.
    matrix.resize(row);
    for (int i = 0; i < row; ++i) {
        matrix[i].resize(column);
    } //makes the vector the desired size by using .resize
    std::cout << "Please enter each element for the row." << '\n';
    int r = 0;
    while (r < row) { //asks user for the elements in each row of the matrix. Will repeat while r < row.
        int c = 0;
        std::cout << "Row " << r + 1 << ": ";
        std::getline(std::cin, input);
        std::stringstream convert(input);
        while (true) { //loops indefinately, until each element has a double.
            if (convert >> matrix[r][c]) { //checks to see if input can be converted into a double
                ++c; //moves to next column
            }
            else {
                break;
            }
            if (c == column) { //once the last column has a double, will break out of while loop.
                ++r; //moves to next row
                break;
            }
        }
    }
    while (true) { //asks user to select which operation they would like to do to the matrix.
        std::cout << "Select which operation you would like to use on the matrix. " << '\n';
        std::cout << "0) Print matrix" << '\n';
        std::cout << "1) Matrix addition and subtraction" << '\n';
        std::cout << "2) Matrix multiplication" << '\n';
        std::cout << "3) Gaussian elimination" << '\n';
        std::cout << "Selection? ";
        std::getline(std::cin, input);
        std::stringstream convert(input);
        int selection;
        if (convert >> selection) {
            if (selection == 0) { //allows user to print their matrix in all its glory!
                print(matrix, row, column);
                break;
            }
            else if (selection == 1) {
                add(matrix, row, column); //calls the add function, which will add to user inputed matrices.
                break; //breaks out of infite while loop.
            }
            else if (selection ==2 ) {
                multi(matrix, row, column);
                break;
            }
            else if (selection == 3) {
                e_r_o(matrix, row, column);
                break;
            }
        }
        std::cout << "Please enter an appropriate selection." << '\n';
    }
    std::cout << "Would you like to rerun the program?" << std::endl; //gives user the option to rerun program by using recursion.
    std::cout << "Y/N? ";
    std::getline(std::cin, input);
    if (input == "y" || input == "Y") {
        return main();
    }
    return 0;
}
/*
 * Allows for the addition and subtraction, based on user choice, of two matrices. The first one is taken from the main, along with
 * the row and column length of the first matrix. Using a multidimensional vector, a second matrix is made with the same dimensions
 * as the first matrix. User is then asked to input each element. Finally, the matrices are either added or subtracted, and then
 * the result is printed out, using the print function.
 */
void add(std::vector < std::vector <double> > nom, int row, int column) {
    std::cout << "Please enter the elements for the row. Note: in order to add or subtract matrices, the dimensions of both must be the same."
            " The dimensions of the first matrix you entered will be used for this one." << '\n';
    //using same method to acquire details of second matrix.
    std::string input;
    std::vector <std::vector <double> > nom2;
    nom2.resize(row);
    for (int i = 0; i < row; ++i) {
        nom2[i].resize(column);
    }
    int r = 0;
    while (r < row) {
        int c = 0;
        std::cout << "Row " << r+1 << ": ";
        std::getline(std::cin, input);
        std::stringstream convert(input);
        while (true) {
            if (convert >> nom2[r][c]) {
                ++c;
            }
            else {
                break;
            }
            if (c == column) {
                ++r;
                break;
            }
        }
    }
    std::cout << "Addition or subtraction? "; //user can chose to add or subtract.
    std::getline(std::cin, input);
    if (input == "Add" || input == "add" || input == "Addition" || input == "addition") {
        for (int i = 0; i < row; ++i) {
            for (int j = 0; j < column; ++j) {
                nom [i][j] += nom2 [i][j]; //adds each corresponding element of the two matrices together. Goes row by row.
            }
        }
        print(nom, row, column);
    }
    else if (input == "Subtract" || input == "subtract" || input == "Subtraction" || input == "subtraction") {
        for (int i = 0; i < row; ++i) {
            for (int j = 0; j < column; ++j) {
                nom [i][j] -= nom2 [i][j]; //same as above, just with subtraction.
            }
        }
        print(nom, row, column);
    }
    else {
        std::cout << "Please choose to add or subtract." << '\n';
    }
}
/*
 * Uses Gaussian-Jordan elimination to put the matrix into the reduced row-echelon form. It then prints out the matrix.
 */
void e_r_o(std::vector < std::vector <double> > nom, int row, int column) {
    //puts the matrix into row-echelon form.
    int a = 0, b = 0, c = 1;
    while (a < row - 1) {
        if (nom [a][b] != 0) {
            int y = 0;
            std::vector <double> holder;
            holder.resize(row - 1);
            for (int i = c; i < row; ++i) {
                holder [y] = (nom [i][b]) / (nom [a][b]);
                ++y;
            }
            int z = 0;
            for (int i = c; i < row; ++i) {
                for (int j = b; j < column; ++j) {
                    nom [i][j] -= holder [z] * nom [a][j];
                }
                ++z;
            }
        }
        ++a;
        ++b;
        ++c;
    }
    //makes leading element for each row a leading one.
    for (int i = 0; i < row; ++i) {
        double k = nom [i][i];
        for (int j = 0; j < column; ++j) {
            nom [i][j] /= k;
        }
    }
    //makes the row-echelon formed matrix into a reduced row-echelon form.
    int d = row - 1, e = column - 2, f = row - 2;
    while (d > 0) {
        if (nom [d][e] != 0) {
            int y = 0;
            std::vector <double> holder;
            holder.resize(row - 1);
            for (int i = f; i > -1; --i) {
                holder [y] = (nom [i][e]) / (nom [d][e]);
                ++y;
            }
            int z = 0;
            for (int i = f; i > -1; --i) {
                for (int j = (column - 1); j > -1; --j) {
                    nom [i][j] -= holder [z] * nom [d][j];
                }
                ++z;
            }
        }
        --d;
        --e;
        --f;
    }
    print (nom, row, column);
}
/*
 * Multiplies two matrices together, and then prints out the product. Gets the first matrix from the parameter, and the second
 * is created by the user.
 */
void multi(std::vector < std::vector <double> > nom, int row1, int column1) {
    std::cout << "Please enter the dimensions of the second matrix. Note: The number of columns of the first matrix must "
            "equal the number of rows of the second matrix." << '\n';
    std::string input;
    int row2, column2;
    while (true) { //asks for number of rows. Checks to make sure it equals the number of columns in the first matrix.
        std::cout << "Number of rows (must be same as number of columns of first matrix!): ";
        std::getline(std::cin, input);
        std::stringstream convert (input);
        if (convert >> row2) {
            if (row2 == column1) {
                break;
            }
        }
        std::cout << "Please enter an appropriate value." << '\n';
    }
    while (true) { //asks for number of columns.
        std::cout << "Number of columns: ";
        std::getline(std::cin, input);
        std::stringstream convert (input);
        if (convert >> column2) {
            if (column2 != 0) {
                break;
            }
        }
        std::cout << "Please enter an appropriate value." << '\n';
    }
    std::vector < std::vector <double> > nom2; //creates the second matrix based off the entered dimensions.
    nom2.resize(row2);
    for (int i = 0; i < row2; ++i) {
        nom2[i].resize(column2);
    }
    std::cout << "Please enter the elements for each row." << '\n';
    int r = 0;
    while (r < row2) { //User enters each element for each row. Has checks in place to make sure user enters doubles.
        int c = 0;
        std::cout << "Row " << r+1 << ": ";
        std::getline(std::cin, input);
        std::stringstream convert(input);
        while (true) {
            if (convert >> nom2[r][c]) {
                ++c;
            }
            else {
                break;
            }
            if (c == column2) {
                ++r;
                break;
            }
        }
    }
    std::vector < std::vector <double> > nom3; //creates a third matrix to hold of the values of other two matrices multiplied.
    nom3.resize(row1); //has row1 rows, and column 2 columns.
    for (int i = 0; i < row1; ++i) {
        nom3[i].resize(column2);
    }
    /*
     * Algorithm for multiplying the two matrices. Multiples the corresponding element of the ith row of the 1st matrix and jth column
     * of the 2nd matrix. Adds them together, and places the final number into the a(i,j) element of the product matrix.
     */
    int z = 0;
    while (z < row1) {  //Z is used to track the row number for the 3rd and 1st matrix. Stops once it equals row1.
        for (int a = 0; a < column2; ++a) { //Used to track the column of the 3rd and 2nd matrix. Stops once it equals column2.
            for (int b = 0; b < row2; ++b) { //Used to track the column for the 1st matrix, and the row for the 2nd matrix.
                nom3[z][a] += nom[z][b] * nom2[b][a]; //Multiplies the elements together, then adds the product to the corresponding element in nom3.
            }
        }
        ++z;
    }
    print(nom3, row1, column2);
}

/*
 * Prints each element of the matrix.
 */
void print(std::vector < std::vector <double> > nom, int row, int column) {
    for (int i = 0; i < row; ++i) {
        for (int j = 0; j < column; ++j) {
            std::cout << nom[i][j] << " ";
        }
        std::cout << std::endl;
    }
}
 
Last edited:
Top