Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdlib>
- #include <cctype>
- #include <cstring>
- using namespace std;
- int main()
- {
- vector<vector<double> > rows;
- vector<double> columns;
- char str[80], *ptr;
- cout << "Enter value of matrix element or key-letters\n"
- << "[N] to start typing next matrix line\n"
- << "[Q] to stop typing\n\n"
- << "First line:\n";
- do {
- cout << ">> ";
- cin >> str;
- if (strtod(str, &ptr))
- columns.push_back(strtod(str, &ptr));
- else if (strchr("n", tolower(str[0])) && !isalpha(tolower(str[1]))) {
- cout << "Next line:\n";
- rows.push_back(columns);
- columns.clear();
- }
- else if (strchr("q", tolower(str[0])) && !isalpha(tolower(str[1]))) {
- cout << "Quitting...\n";
- rows.push_back(columns);
- break;
- }
- else {
- cout << "Enter only element value or key-letters!\n";
- continue;
- }
- } while (1);
- unsigned int i, j;
- cout << "\t\t\tEntered matrix:\n\n";
- for (i = 0; i < rows.size(); i++) {
- if (rows[i].size() == 0) {
- cout << "\t[empty line]\n";
- continue;
- }
- for (j = 0; j < rows[i].size(); j++)
- cout << rows[i][j] << "\t";
- cout << "\n\n";
- }
- cout << "\n\n";
- //system("pause"); // - В Бубунтах пауза не та, но и так сойдёт
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement