Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
It is required to develop a program to do Matrix operations. The program use a defined string format to represent the matrix in the user input and output sections. For the following matrix: examplee : the user input the string representation of the Matrix : ex:[10 2.13 3;-5 0 4;16.5 1 8] In the program, the user enters a matrix in the defined string format then asked to enter an operator

so i can't convert this string to an array to make operations as sum or multiply.

What I have tried:

using namespace std;

int main() { 

    int i, j, n; 
    string s1; 
    float m1[100][100]; 

    getline(cin, s1);

    for (int i = 0; i < 100; i++) { 
        for (n = 0; n < s1.length(); n++) { 
            if (isspace(s1.at(i)));
        } 
    }
}
Posted
Updated 26-Apr-19 23:04pm
v2

You first need to split the string using the semi-colon as the separator,. That will give you a string of numbers for each row. Then split each substring using the comma as separator which will give the numbers for each column. You can then allocate the array for the matrix. You then need to take each number in turn, convert it to a double value and store it in the relevant cell of the matrix. See basic_string Class | Microsoft Docs[^] to see how to find the separator characters.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900