Я и моя команда пытались выполнить следующее задание, мы не можем заставить его работать с arg и parseline. Это код, который у нас пока есть.
include iostream
include string
include fstream
include iomanip
using namespace std;
const string ID = "Allan Ramirez - CS 1336 - Assignment 26";
int main()
{
//In and out file objects
ifstream in;
ofstream out;
//Variable to read values
string line;
//Variable to find sum
int sum = 0;
//Varible for row and column count
int row, col;
//File path
in.open("C:/Users/deept/Desktop/input.txt");
out.open("C:/Users/deept/Desktop/output.txt");
//File open error check
if (!in || !out)
{
cout << "file cannot be found. " << endl;
return 0;
}
//If open
else
{
//Read first line
in >> line;
//Set row and column
row=stoi(line.substr(0));
col = stoi(line.substr(2));
//Declare array
int** val = new int*[row];
for (int i = 0; i < row; ++i)
val[i] = new int[col];
int j = 0,i=0;
//Read to end
while (!in.eof())
{
//Each word set into array
in >> line;
if (j < col)
{
val[i][j] =stoi(line);
//Find sum
sum += val[i][j];
j++;
}
else {
j = 0;
//Write into output array
out << sum << " " ;
sum = 0;
i++;
val[i][j] =stoi(line);
sum += val[i][j];
j++;
}
}
//Close file
in.close();
out.close();
//Console output
cout << ID << endl;
cout << "Number of rows: " << row << endl;
cout << "Number of columns: " << col << endl;
cout << "Average of rows: ";
sum = 0;
double avg = 0;
for (i = 0; i< col; i++)
{
for (j = 0; j < row; j++)
{
sum+= val[i][j];
}
avg = sum / row;
cout << setprecision(1) << avg << " ";
sum = 0;
avg = 0;
}
cout << endl;
cout << "Average of columns: ";
sum = 0;
avg = 0;
for (i = 0; i< row; i++)
{
for (j = 0; j < col; j++)
{
sum += val[i][j];
}
avg = sum / col;
cout << setprecision(1) << avg << " ";
sum = 0;
avg = 0;
}
cout << endl;
}
return 0;
}