C++ program on visual studio. numbers inside (data.txt) could not attach the fil
ID: 3798211 • Letter: C
Question
C++ program on visual studio.
numbers inside (data.txt) could not attach the file.
16
17
9
16
0
17
19
16
24
3
8
12
14
5
20
6
2
11
20
17
2
11
4
2
3
7
21
16
18
20
22
1
21
13
19
12
17
24
10
19
3
11
22
8
23
14
16
11
3
18
22
19
12
7
12
9
23
16
4
3
16
10
15
17
13
6
15
17
14
23
21
5
15
4
20
0
6
1
18
23
4
23
9
4
6
15
16
1
6
8
19
14
1
23
12
13
18
7
4
16
Explanation / Answer
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
int row = 0, col = 0, num_of_rows = 0, num_of_cols = 0;
stringstream ss;
ifstream infile("testfile.pgm", ios::binary);
string inputLine = "";
getline(infile,inputLine);
if(inputLine.compare("P5") != 0) cerr << "Version error" << endl;
cout << "Version : " << inputLine << endl;
getline(infile,inputLine);
cout << "Comment : " << inputLine << endl;
ss << infile.rdbuf();
ss >> num_of_cols >> num_of_rows;
cout << num_of_cols << " columns and " << num_of_rows << " rows" << endl;
int max_val;
ss >> max_val;
cout<<max_val;
char pixel;
unsigned int pixel-value[num_of_rows][num_of_cols];
unsigned int integral[num_of_rows][num_of_cols];
for(row=0;row<num_of_rows;row++)
{
for(col=0;col<num_of_colss;col++)
{
ss>>pixel;
pixel_value[row][col]=pixel;
}
cout<<endl;
}
int **pixel_value = new int*[num_of_rows];
for(int i = 0; i < num_of_rows; ++i)
{
pixel_value[i] = new int[num_of_cols];
}
int **integral = new int*[num_of_rows];
for(int i = 0; i < num_of_rows; ++i)
{
integral[i] = new int[num_of_cols];
}
integral[0][0]=pixel_value[0][0];
for(int i=1; i<num_of_cols;i++)
{
integral[0][i]=integral[0][i-1]+pixel_value[0][i];
}
for (int i=1;i<num_of_rows; i++)
{
integral[i][0]=integral[i-1][0]+pixel_value[i][0];
}
for (int i = 1; i < num_of_rows; i++)
{
for (int j = 1; j < num_of_cols; j++)
{
integral[i][j] = integral[i - 1 ,j] + integral [i,j - 1] - integral[i - 1,j - 1] + pixel_value[i,j];
}
}
ofstream output1("pixel_value.txt");
for (int k=0; k<num_of_rows; k++)
{
for (int r=0; r<num_of_cols; r++)
{
output1 << pixel_value[k][r] << " ";
}
output1 << ";" << endl;
}
ofstream output2("integral_value.txt");
for (int a=0; a<num_of_rows; a++)
{
for (int b=0; b<num_of_cols; b++)
{
output2 << integral[a][b] << " ";
}
output2 << ";" << endl;
}
for(int i = 0; i < num_of_rows; ++i) {
delete [] pixel_value[i];
}
delete [] pixel_value;
for(int i = 0; i < num_of_rows; ++i) {
delete [] integral[i];
}
delete [] integral;
infile.close();
system("pause");
return 0;
void histo_2 (int values[], int sz)
{
int level = max_arr(values,sz);
for(; level > 0; level—) {
for(int i = 0; i < sz; i++)
if (values[i] >= level) cout << "**** ";
else cout << " ";
cout << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.