#include <iostream> #include <fstream> using namespace std; class RGB { public:
ID: 2247110 • Letter: #
Question
#include <iostream>
#include <fstream>
using namespace std;
class RGB
{
public:
unsigned int r,g,b;
RGB(){
r = 0, g = 0, b = 0;
}
RGB(unsigned int red, unsigned int green, unsigned int blue){
r = red;
g = green;
b = blue;
}
unsigned int getred(){
return r;
}
unsigned int getgreen(){
return g;
}
unsigned int getblue(){
return b;
}
};
class Imageppm: public RGB
{
public:
unsigned int h,w,pixmap;
Imageppm(unsigned int height, unsigned int width)
{
h = height;
w = width;
pixmap = RGB[h];
for(unsigned int i = 0; i < w; i++){
pixmap[i] = RGB[w];
}
}
void writeppm(string filename){
ofstream out(filename.c_str());
out << "P3 " << endl;
out << "Created by " << endl;
out << h << " " << w << endl;
out << 255 << endl;
out << " " << endl;
for(int i = 0; i < h; h++){
for(int k = 0; k < w; k++){
}
}
}
};
int main()
{
return 0;
}
********************help c++ errors 42 unexpected primary expession ' token line 44 invalid type unsigned int for array subscript
Explanation / Answer
Solution===========================
#include <iostream>
#include <fstream>
using namespace std;
class RGB
{
public:
unsigned int r,g,b;
RGB(){
r = 0, g = 0, b = 0;
}
RGB(unsigned int red, unsigned int green, unsigned int blue){
r = red;
g = green;
b = blue;
}
unsigned int getred(){
return r;
}
unsigned int getgreen(){
return g;
}
unsigned int getblue(){
return b;
}
};
//It appears you are trying to create a 2d matrix of RGB class i.e a Pixelmap
//We will require the use of pointers to do it
class Imageppm: public RGB
{
public:
unsigned int h,w;
RGB **pixmap; //Can point to an array of pointers
Imageppm(unsigned int height, unsigned int width)
{
h = height;
w = width;
pixmap= new RGB*[h]; //Array of pointers of size H
for(unsigned int i = 0; i < w; i++){
//Each array pointer points to an array of size W
//Effectively making it into a HxW array
pixmap[i]=new RGB[w];
}
}
void writeppm(string filename){
ofstream out(filename.c_str());
out << "P3 " << endl;
out << "Created by " << endl;
out << h << " " << w << endl;
out << 255 << endl;
out << " " << endl;
for(int i = 0; i < h; h++){
for(int k = 0; k < w; k++){
}
}
}
};
int main()
{
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.