Fix a C++ Code Problem Todo: I try to output the information in function "void initialiseAsDefaultDiagonalLine(icon myIc
Posted: Sat Nov 27, 2021 2:19 pm
Fix a C++ Code Problem
Todo: I try to output the information in function "void
initialiseAsDefaultDiagonalLine(icon myIcon)" and display the info
by function "void showIconDetail(const icon aicon)". By using
the code as shown in the last three lines, but the output just
keeps going and also doesn't display any number given in the
function. HELP FIX PLEASE!!!
CODE:
#include <iostream>
using namespace std;
// Declare class name
class pixel;
class icon;
// Develop a class to encapsulate the data associated with the
concept of a graphic pixel
// Declare all variables needed for the pixel
class pixel {
public:
float x;
float y;
float Brightness;
};
// Develop a class that encapsulate the concept of an icon
class icon {
public:
int idNumberOfPixels; // integer to hold the id
number
pixel thePixels[16]; // Contain up to 16 pixels
};
// Function passed an instance of a pixel as it's argument, to
report to screen the contents of pixel it has been given
void showPixelDetail(const pixel& aPixel){
cout<<"\nCoordinate =
("<<aPixel.x<<", "<<aPixel.y<<") with
brightness = "<<aPixel.Brightness<<"";
}
// Function passes an instance of an icon as it's argument, and use
the showPixelDetail function to list the details of the icon's
pixel
void showIconDetail(const icon aicon){
float totalPixel(0);
cout<<"\n\n--------The detail contain in
icon are---------\n";
for(int i=1;i<=aicon.idNumberOfPixels;i++)
{
cout<<"\n\nPixel
"<<i;
showPixelDetail(aicon.thePixels);
}
}
// Hide the details of pixels so to not clutter the main code
void initialiseAsDefaultDiagonalLine(icon myIcon){
myIcon.idNumberOfPixels = 7;
myIcon.thePixels[1].x = 1;
myIcon.thePixels[1].y = 1;
myIcon.thePixels[1].Brightness = 15;
myIcon.thePixels[2].x = 2;
myIcon.thePixels[2].y = 2;
myIcon.thePixels[2].Brightness = 15;
myIcon.thePixels[3].x = 3;
myIcon.thePixels[3].y = 3;
myIcon.thePixels[3].Brightness = 15;
myIcon.thePixels[4].x = 4;
myIcon.thePixels[4].y = 4;
myIcon.thePixels[4].Brightness = 15;
myIcon.thePixels[5].x = 5;
myIcon.thePixels[5].y = 5;
myIcon.thePixels[5].Brightness = 15;
myIcon.thePixels[6].x = 6;
myIcon.thePixels[6].y = 6;
myIcon.thePixels[6].Brightness = 15;
myIcon.thePixels[7].x = 7;
myIcon.thePixels[7].y = 7;
myIcon.thePixels[7].Brightness = 15;
}
int main()
{
// Test if pixel object was correctly implemented
pixel myFirstEverPixel;
myFirstEverPixel.x = 1.1;
myFirstEverPixel.y = 2.2;
myFirstEverPixel.Brightness = 3;
cout<<"\n------The detail of myFirstEverPixel
are-------\n";
showPixelDetail(myFirstEverPixel);
cout<<"\n-----------------------------------------------\n";
// Create a instance called aPixel and print out data contained
within aPixel
pixel aPixel;
aPixel.x = 3.9;
aPixel.y = 4.1;
aPixel.Brightness = 7;
cout<<"\n-----------The detail of aPixel
are------------\n";
showPixelDetail(aPixel);
cout<<"\n-----------------------------------------------\n";
// Create an instance of a pixel called pixelOne and pixelTwo
// Test if the code will understand "=" sign by printing the output
of pixelTwo
pixel pixelOne;
pixelOne.x = 4.4;
pixelOne.y = 5.5;
pixelOne.Brightness = 6;
pixel pixelTwo;
pixelTwo = pixelOne;
cout<<"\n---------The detail of pixelTwo
are------------\n";
showPixelDetail(pixelTwo);
cout<<"\n-----------------------------------------------\n";
// Create an icon instance according to given information, becoming
bright diagonal line on screen
icon myIcon;
initialiseAsDefaultDiagonalLine(myIcon);
showIconDetail(myIcon);
}
Todo: I try to output the information in function "void
initialiseAsDefaultDiagonalLine(icon myIcon)" and display the info
by function "void showIconDetail(const icon aicon)". By using
the code as shown in the last three lines, but the output just
keeps going and also doesn't display any number given in the
function. HELP FIX PLEASE!!!
CODE:
#include <iostream>
using namespace std;
// Declare class name
class pixel;
class icon;
// Develop a class to encapsulate the data associated with the
concept of a graphic pixel
// Declare all variables needed for the pixel
class pixel {
public:
float x;
float y;
float Brightness;
};
// Develop a class that encapsulate the concept of an icon
class icon {
public:
int idNumberOfPixels; // integer to hold the id
number
pixel thePixels[16]; // Contain up to 16 pixels
};
// Function passed an instance of a pixel as it's argument, to
report to screen the contents of pixel it has been given
void showPixelDetail(const pixel& aPixel){
cout<<"\nCoordinate =
("<<aPixel.x<<", "<<aPixel.y<<") with
brightness = "<<aPixel.Brightness<<"";
}
// Function passes an instance of an icon as it's argument, and use
the showPixelDetail function to list the details of the icon's
pixel
void showIconDetail(const icon aicon){
float totalPixel(0);
cout<<"\n\n--------The detail contain in
icon are---------\n";
for(int i=1;i<=aicon.idNumberOfPixels;i++)
{
cout<<"\n\nPixel
"<<i;
showPixelDetail(aicon.thePixels);
}
}
// Hide the details of pixels so to not clutter the main code
void initialiseAsDefaultDiagonalLine(icon myIcon){
myIcon.idNumberOfPixels = 7;
myIcon.thePixels[1].x = 1;
myIcon.thePixels[1].y = 1;
myIcon.thePixels[1].Brightness = 15;
myIcon.thePixels[2].x = 2;
myIcon.thePixels[2].y = 2;
myIcon.thePixels[2].Brightness = 15;
myIcon.thePixels[3].x = 3;
myIcon.thePixels[3].y = 3;
myIcon.thePixels[3].Brightness = 15;
myIcon.thePixels[4].x = 4;
myIcon.thePixels[4].y = 4;
myIcon.thePixels[4].Brightness = 15;
myIcon.thePixels[5].x = 5;
myIcon.thePixels[5].y = 5;
myIcon.thePixels[5].Brightness = 15;
myIcon.thePixels[6].x = 6;
myIcon.thePixels[6].y = 6;
myIcon.thePixels[6].Brightness = 15;
myIcon.thePixels[7].x = 7;
myIcon.thePixels[7].y = 7;
myIcon.thePixels[7].Brightness = 15;
}
int main()
{
// Test if pixel object was correctly implemented
pixel myFirstEverPixel;
myFirstEverPixel.x = 1.1;
myFirstEverPixel.y = 2.2;
myFirstEverPixel.Brightness = 3;
cout<<"\n------The detail of myFirstEverPixel
are-------\n";
showPixelDetail(myFirstEverPixel);
cout<<"\n-----------------------------------------------\n";
// Create a instance called aPixel and print out data contained
within aPixel
pixel aPixel;
aPixel.x = 3.9;
aPixel.y = 4.1;
aPixel.Brightness = 7;
cout<<"\n-----------The detail of aPixel
are------------\n";
showPixelDetail(aPixel);
cout<<"\n-----------------------------------------------\n";
// Create an instance of a pixel called pixelOne and pixelTwo
// Test if the code will understand "=" sign by printing the output
of pixelTwo
pixel pixelOne;
pixelOne.x = 4.4;
pixelOne.y = 5.5;
pixelOne.Brightness = 6;
pixel pixelTwo;
pixelTwo = pixelOne;
cout<<"\n---------The detail of pixelTwo
are------------\n";
showPixelDetail(pixelTwo);
cout<<"\n-----------------------------------------------\n";
// Create an icon instance according to given information, becoming
bright diagonal line on screen
icon myIcon;
initialiseAsDefaultDiagonalLine(myIcon);
showIconDetail(myIcon);
}