SlideShare a Scribd company logo
1 of 8
Download to read offline
Will th ebelow code work andif not please help me fix it. Basically I am taking in a line of code
and we are supposed to use fail state to figure out which kind of format the line will follow. It
will either follow one of two formats. So I am trying to say if while reading in it hits something
that doesn't work it must be the OTHER kind of line. Am I using clear and fail functions
correctly? It is important that when it fails the next value being read in goes into the place where
it failed reading in.
So if it tries to read something in and it fails the next value read in should go into THAT value
and not the next one.
Solution
Reasons:
i) You cannot start read vertexOne or vertexTwo, before you open the stream
ii) Set up your file reading in streams based on the layout of your files, so what you can do is to
have if-else
statements that select the right stream setup bases on the filname.
Program:
#include "Triangle.h"
#include "Graphics.h"
#include "Shape.h"
#include
using namespace std;
Triangle::Triangle()
{
}
Triangle::Triangle(Point pt1, Point pt2, Point pt3, Color color) {
vertexOne = pt1;
vertexTwo = pt2;
vertexThree = pt3;
vertexOneColor = color;
vertexTwoColor = color;
vertexThreeColor = color;
}
Triangle::Triangle(Point pt1, Color col1, Point pt2, Color col2, Point pt3, Color col3)
{
vertexOne = pt1;
vertexOneColor = col1;
vertexTwo = pt2;
vertexTwoColor = col2;
vertexThree = pt3;
vertexThreeColor = col3;
}
void Triangle::setColor(Color col)
{
vertexOneColor = col;
vertexTwoColor = col;
vertexThreeColor = col;
}
void Triangle::setVertexOne(Point pt)
{
vertexOne = pt;
}
void Triangle::setVertexTwo(Point pt)
{
vertexTwo = pt;
}
void Triangle::setVertexThree(Point pt)
{
vertexThree = pt;
}
Point Triangle::getVertexOne()
{
return vertexOne;
}
Point Triangle::getVertexTwo()
{
return vertexTwo;
}
Point Triangle::getVertexThree()
{
return vertexThree;
}
void Triangle::setVertexOneColor(Color col)
{
vertexOneColor = col;
}
void Triangle::setVertexTwoColor(Color col)
{
vertexTwoColor = col;
}
void Triangle::setVertexThreeColor(Color col) {
vertexThreeColor = col;
}
Color Triangle::getVertexOneColor()
{
return vertexOneColor;
}
Color Triangle::getVertexTwoColor()
{
return vertexTwoColor;
}
Color Triangle::getVertexThreeColor()
{
return vertexThreeColor;
}
void Triangle::read(istream& ins)
{
// These are values of the each vertex and color
Point vertex1;
Point vertex2;
Point vertex3;
Color col;
Color vertex1Color;
Color vertex2Color;
Color vertex3Color;
ins >> vertex1 >> vertex1Color >> vertex2 >> vertex2Color >> vertex3;
// Checks whether ins has entered a fail state of not
if (ins.fail())
{
ins.clear();
Triangle(vertex1, vertex2, vertex3, vertex1Color);
}
else
{
ins >> vertex3Color;
Triangle(vertex1, vertex1Color, vertex2, vertex2Color,vertex3, vertex3Color);
}
}
void Triangle::write(ostream& outs)
{
Point out_vertex1 = getVertexOne();
Point out_vertex2 = getVertexTwo();
Point out_vertex3 = getVertexThree();
Color out_vertex1Color = getVertexOneColor();
Color out_vertex2Color = getVertexTwoColor();
Color out_vertex3Color = getVertexThreeColor();
outs << out_vertex1 << " " << out_vertex1Color << " " << out_vertex2 << " " <<
out_vertex2Color << " " << out_vertex3 << " " << out_vertex3Color;
}
istream& operator >> (istream& ins, Triangle& tri)
{
tri.read(ins);
return ins;
}
ostream& operator << (ostream& outs, Triangle tri)
{
tri.write(outs);
return outs;
}
void Triangle::draw (Graphics& drawer)
{
int xa = checkRange(getVertexOne().getX());
int ya = checkRange(getVertexOne().getY());
int xb = checkRange(getVertexTwo().getX());
int yb = checkRange(getVertexTwo().getY());
int xc = checkRange(getVertexThree().getX());
int yc = checkRange(getVertexThree().getY());
float red1 = (float)(getVertexOneColor().getRed()/255.0);
float green1 = (float)(getVertexOneColor().getGreen()/255.0);
float blue1 = (float)(getVertexOneColor().getBlue()/255.0);
float red2 = (float)(getVertexTwoColor().getRed()/255.0);
float green2 = (float)(getVertexTwoColor().getGreen()/255.0);
float blue2 = (float)(getVertexTwoColor().getBlue()/255.0);
float red3 = (float)(getVertexThreeColor().getRed()/255.0);
float green3 = (float)(getVertexThreeColor().getGreen()/255.0);
float blue3 = (float)(getVertexThreeColor().getBlue()/255.0);
float a01, a02, a03, b01, b02, b03, c01, c02, c03, beta1, beta2, beta3;
float lowX = 0, lowY = 0, highX = 0, highY = 0, i, j, R, G, B, t1, t2, t3;
float triangleArea = 0;
a01 = (float)(ya - yb);
a02 = (float)(ya - yc);
a03 = (float)(yb - yc);
b01 = (float)(xb - xa);
b02 = (float)(xc - xa);
b03 = (float)(xc - xb);
c01 = -(a01 * (xa+xb)+ b01 * (ya + yb)) / 2;
c02 = -(a02 *(xa+xc) + b02 * (ya + yc)) / 2;
c03 = -(a03 *(xb+xc) + b03 * (yb + yc)) / 2;
if (evalFunc(xc,yc, (int)a01, (int)b01, (int)c01) < 0)
{
a01 = a01 * (-1);
b01 = b01 * (-1);
c01 = c01 * (-1);
}
if (evalFunc(xb,yb, (int)a02, (int)b02, (int)c02) < 0)
{
a02 = a02 * (-1);
b02 = b02 * (-1);
c02 = c02 * (-1);
}
if (evalFunc(xa,ya, (int)a03, (int)b03, (int)c03) < 0)
{
a03 = a03 * (-1);
b03 = b03 * (-1);
c03 = c03 * (-1);
}
if (xa > xb)
{
highX = (float)xa;
}
else
{
highX = (float)xb;
}
if (xc > highX)
{
highX = (float)xc;
}
if (ya > yb)
{
highY = (float)ya;
}
else
{
highY = (float)yb;
}
if (yc > highY)
{
highY = (float)yc;
}
if (xa < xb)
{
lowX = (float)xa;
}
else
{
lowX = (float)xb;
}
if (xc < lowX)
{
lowX = (float)xc;
}
if (ya < yb)
{
lowY = (float)ya;
}
else
{
lowY = (float)yb;
}
if (yc < lowY)
{
lowY = (float)yc;
}
triangleArea = triArea(xa, ya, xb, yb, xc, yc);
for (i = lowX; i < (highX+1); i++) {
for (j = lowY; j < (highY+1); j++) {
t1 = (float)evalFunc((int)i,(int)j, (int)a01, (int)b01, (int)c01);
t2 = (float)evalFunc((int)i,(int)j, (int)a02, (int)b02, (int)c02);
t3 = (float)evalFunc((int)i,(int)j, (int)a03, (int)b03, (int)c03);
if ((t1 >= 0)&&(t2 >= 0)&&(t3 >= 0)){
t1 = triArea(xb, yb, xc, yc, (int)i, (int)j);
t2 = triArea(xc, yc, xa, ya, (int)i, (int)j);
t3 = triArea(xa, ya, xb, yb, (int)i, (int)j);
beta1 = triArea(xb, yb, xc, yc, (int)i, (int)j)/triangleArea;
beta2 = triArea(xc, yc, xa, ya, (int)i, (int)j)/triangleArea;
beta3 = triArea(xa, ya, xb, yb, (int)i, (int)j)/triangleArea;
R = (beta1*red1 + beta2*red2 + beta3*red3) * 255;
G = (beta1*green1 + beta2*green2 + beta3*green3) * 255;
B = (beta1*blue1 + beta2*blue2 + beta3*blue3) * 255;
drawer.setPixel((int)i,(int)j,Color((int)R,(int)G,int(B)));
}
}
}
}
int Triangle::checkRange(int val)
{
if (val < 0)
return 0;
else if (val > DIMENSION)
return DIMENSION;
else
return val;
}
int Triangle::evalFunc(int p, int q, int a, int b, int c)
{
int e = a*p+b*q+c;
return(e);
}
float Triangle::triArea(int xa, int ya, int xb, int yb, int xref, int yref) {
xa -= xref;
xb -= xref;
ya -= yref;
yb -= yref;
return((float)(sqrt(pow((double)(yb*xa)-(xb*ya), (double)2))*0.5));
}

More Related Content

Similar to Will th ebelow code work andif not please help me fix it. Basically .pdf

Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview QuestionsGradeup
 
Floating point basicsThe core idea of floating-point representatio.pdf
Floating point basicsThe core idea of floating-point representatio.pdfFloating point basicsThe core idea of floating-point representatio.pdf
Floating point basicsThe core idea of floating-point representatio.pdfinfo235816
 
I have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxI have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxdelciegreeks
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfssuser37b0e0
 
Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Ziyauddin Shaik
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding ChallengeSunil Yadav
 
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docxchristiandean12115
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerJanie Clayton
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureNurjahan Nipa
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Introduction to programming - class 3
Introduction to programming - class 3Introduction to programming - class 3
Introduction to programming - class 3Paul Brebner
 

Similar to Will th ebelow code work andif not please help me fix it. Basically .pdf (20)

Unit3 C
Unit3 C Unit3 C
Unit3 C
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
Floating point basicsThe core idea of floating-point representatio.pdf
Floating point basicsThe core idea of floating-point representatio.pdfFloating point basicsThe core idea of floating-point representatio.pdf
Floating point basicsThe core idea of floating-point representatio.pdf
 
I have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docxI have question in c++ program I need the answer as soon as possible.docx
I have question in c++ program I need the answer as soon as possible.docx
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdf
 
Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )Introduction to python programming ( part-2 )
Introduction to python programming ( part-2 )
 
LeetCode April Coding Challenge
LeetCode April Coding ChallengeLeetCode April Coding Challenge
LeetCode April Coding Challenge
 
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
1.1 Nested Loops – Lab3C.cppLoops often have loops inside .docx
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Introduction to programming - class 3
Introduction to programming - class 3Introduction to programming - class 3
Introduction to programming - class 3
 
Arrays
ArraysArrays
Arrays
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 

More from michaelazach6427

Compare and contrast protein import into the ER and into the nucleus.pdf
Compare and contrast protein import into the ER and into the nucleus.pdfCompare and contrast protein import into the ER and into the nucleus.pdf
Compare and contrast protein import into the ER and into the nucleus.pdfmichaelazach6427
 
Discuss some of the various ways MySQL allows you to explore a datab.pdf
Discuss some of the various ways MySQL allows you to explore a datab.pdfDiscuss some of the various ways MySQL allows you to explore a datab.pdf
Discuss some of the various ways MySQL allows you to explore a datab.pdfmichaelazach6427
 
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdf
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdfDimitri and Rita eat some donuts for breakfast and then spend the mo.pdf
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdfmichaelazach6427
 
detail the importance of cell culture to the field of virologySo.pdf
detail the importance of cell culture to the field of virologySo.pdfdetail the importance of cell culture to the field of virologySo.pdf
detail the importance of cell culture to the field of virologySo.pdfmichaelazach6427
 
Ageism disproportionately affects women since they outlive me. T.pdf
Ageism disproportionately affects women since they outlive me. T.pdfAgeism disproportionately affects women since they outlive me. T.pdf
Ageism disproportionately affects women since they outlive me. T.pdfmichaelazach6427
 
Could you please help me on this questionThe duty cycle of a conv.pdf
Could you please help me on this questionThe duty cycle of a conv.pdfCould you please help me on this questionThe duty cycle of a conv.pdf
Could you please help me on this questionThe duty cycle of a conv.pdfmichaelazach6427
 
A random sample of five observations from the first population resul.pdf
A random sample of five observations from the first population resul.pdfA random sample of five observations from the first population resul.pdf
A random sample of five observations from the first population resul.pdfmichaelazach6427
 
Biomembranes contain many different types of lipid molecules. What a.pdf
Biomembranes contain many different types of lipid molecules. What a.pdfBiomembranes contain many different types of lipid molecules. What a.pdf
Biomembranes contain many different types of lipid molecules. What a.pdfmichaelazach6427
 
2. The Lorenz curve measures inequality in person income distributio.pdf
2. The Lorenz curve measures inequality in person income distributio.pdf2. The Lorenz curve measures inequality in person income distributio.pdf
2. The Lorenz curve measures inequality in person income distributio.pdfmichaelazach6427
 
1.) In some forms of epigenetic modification, when a gene is “marked.pdf
1.) In some forms of epigenetic modification, when a gene is “marked.pdf1.) In some forms of epigenetic modification, when a gene is “marked.pdf
1.) In some forms of epigenetic modification, when a gene is “marked.pdfmichaelazach6427
 
The visual system that a mountain biker would use to identify changes.pdf
The visual system that a mountain biker would use to identify changes.pdfThe visual system that a mountain biker would use to identify changes.pdf
The visual system that a mountain biker would use to identify changes.pdfmichaelazach6427
 
Which of the following is NOT a benefit of breathing through the nose.pdf
Which of the following is NOT a benefit of breathing through the nose.pdfWhich of the following is NOT a benefit of breathing through the nose.pdf
Which of the following is NOT a benefit of breathing through the nose.pdfmichaelazach6427
 
Which is not a secure MAC address learning for port securityA. St.pdf
Which is not a secure MAC address learning for port securityA. St.pdfWhich is not a secure MAC address learning for port securityA. St.pdf
Which is not a secure MAC address learning for port securityA. St.pdfmichaelazach6427
 
what is the transport process for a methane gas leakSolutionS.pdf
what is the transport process for a methane gas leakSolutionS.pdfwhat is the transport process for a methane gas leakSolutionS.pdf
what is the transport process for a methane gas leakSolutionS.pdfmichaelazach6427
 
Summarize the article Trading liberty for illusions by Wendy Kam.pdf
Summarize the article Trading liberty for illusions by Wendy Kam.pdfSummarize the article Trading liberty for illusions by Wendy Kam.pdf
Summarize the article Trading liberty for illusions by Wendy Kam.pdfmichaelazach6427
 
what is a shared derived charterer and how is it useful for construc.pdf
what is a shared derived charterer and how is it useful for construc.pdfwhat is a shared derived charterer and how is it useful for construc.pdf
what is a shared derived charterer and how is it useful for construc.pdfmichaelazach6427
 
TF Unsaturated fatty acids have double or triple bonds creative kin.pdf
TF Unsaturated fatty acids have double or triple bonds creative kin.pdfTF Unsaturated fatty acids have double or triple bonds creative kin.pdf
TF Unsaturated fatty acids have double or triple bonds creative kin.pdfmichaelazach6427
 
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdf
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdfsamples, then compuie ine im samples, then cop me 9. Patient Waiting .pdf
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdfmichaelazach6427
 
The figure below shows two normal distributions. A and B. The distrib.pdf
The figure below shows two normal distributions. A and B. The distrib.pdfThe figure below shows two normal distributions. A and B. The distrib.pdf
The figure below shows two normal distributions. A and B. The distrib.pdfmichaelazach6427
 
Random signal analysis question (19). Not sure whether true or false.pdf
Random signal analysis question (19). Not sure whether true or false.pdfRandom signal analysis question (19). Not sure whether true or false.pdf
Random signal analysis question (19). Not sure whether true or false.pdfmichaelazach6427
 

More from michaelazach6427 (20)

Compare and contrast protein import into the ER and into the nucleus.pdf
Compare and contrast protein import into the ER and into the nucleus.pdfCompare and contrast protein import into the ER and into the nucleus.pdf
Compare and contrast protein import into the ER and into the nucleus.pdf
 
Discuss some of the various ways MySQL allows you to explore a datab.pdf
Discuss some of the various ways MySQL allows you to explore a datab.pdfDiscuss some of the various ways MySQL allows you to explore a datab.pdf
Discuss some of the various ways MySQL allows you to explore a datab.pdf
 
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdf
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdfDimitri and Rita eat some donuts for breakfast and then spend the mo.pdf
Dimitri and Rita eat some donuts for breakfast and then spend the mo.pdf
 
detail the importance of cell culture to the field of virologySo.pdf
detail the importance of cell culture to the field of virologySo.pdfdetail the importance of cell culture to the field of virologySo.pdf
detail the importance of cell culture to the field of virologySo.pdf
 
Ageism disproportionately affects women since they outlive me. T.pdf
Ageism disproportionately affects women since they outlive me. T.pdfAgeism disproportionately affects women since they outlive me. T.pdf
Ageism disproportionately affects women since they outlive me. T.pdf
 
Could you please help me on this questionThe duty cycle of a conv.pdf
Could you please help me on this questionThe duty cycle of a conv.pdfCould you please help me on this questionThe duty cycle of a conv.pdf
Could you please help me on this questionThe duty cycle of a conv.pdf
 
A random sample of five observations from the first population resul.pdf
A random sample of five observations from the first population resul.pdfA random sample of five observations from the first population resul.pdf
A random sample of five observations from the first population resul.pdf
 
Biomembranes contain many different types of lipid molecules. What a.pdf
Biomembranes contain many different types of lipid molecules. What a.pdfBiomembranes contain many different types of lipid molecules. What a.pdf
Biomembranes contain many different types of lipid molecules. What a.pdf
 
2. The Lorenz curve measures inequality in person income distributio.pdf
2. The Lorenz curve measures inequality in person income distributio.pdf2. The Lorenz curve measures inequality in person income distributio.pdf
2. The Lorenz curve measures inequality in person income distributio.pdf
 
1.) In some forms of epigenetic modification, when a gene is “marked.pdf
1.) In some forms of epigenetic modification, when a gene is “marked.pdf1.) In some forms of epigenetic modification, when a gene is “marked.pdf
1.) In some forms of epigenetic modification, when a gene is “marked.pdf
 
The visual system that a mountain biker would use to identify changes.pdf
The visual system that a mountain biker would use to identify changes.pdfThe visual system that a mountain biker would use to identify changes.pdf
The visual system that a mountain biker would use to identify changes.pdf
 
Which of the following is NOT a benefit of breathing through the nose.pdf
Which of the following is NOT a benefit of breathing through the nose.pdfWhich of the following is NOT a benefit of breathing through the nose.pdf
Which of the following is NOT a benefit of breathing through the nose.pdf
 
Which is not a secure MAC address learning for port securityA. St.pdf
Which is not a secure MAC address learning for port securityA. St.pdfWhich is not a secure MAC address learning for port securityA. St.pdf
Which is not a secure MAC address learning for port securityA. St.pdf
 
what is the transport process for a methane gas leakSolutionS.pdf
what is the transport process for a methane gas leakSolutionS.pdfwhat is the transport process for a methane gas leakSolutionS.pdf
what is the transport process for a methane gas leakSolutionS.pdf
 
Summarize the article Trading liberty for illusions by Wendy Kam.pdf
Summarize the article Trading liberty for illusions by Wendy Kam.pdfSummarize the article Trading liberty for illusions by Wendy Kam.pdf
Summarize the article Trading liberty for illusions by Wendy Kam.pdf
 
what is a shared derived charterer and how is it useful for construc.pdf
what is a shared derived charterer and how is it useful for construc.pdfwhat is a shared derived charterer and how is it useful for construc.pdf
what is a shared derived charterer and how is it useful for construc.pdf
 
TF Unsaturated fatty acids have double or triple bonds creative kin.pdf
TF Unsaturated fatty acids have double or triple bonds creative kin.pdfTF Unsaturated fatty acids have double or triple bonds creative kin.pdf
TF Unsaturated fatty acids have double or triple bonds creative kin.pdf
 
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdf
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdfsamples, then compuie ine im samples, then cop me 9. Patient Waiting .pdf
samples, then compuie ine im samples, then cop me 9. Patient Waiting .pdf
 
The figure below shows two normal distributions. A and B. The distrib.pdf
The figure below shows two normal distributions. A and B. The distrib.pdfThe figure below shows two normal distributions. A and B. The distrib.pdf
The figure below shows two normal distributions. A and B. The distrib.pdf
 
Random signal analysis question (19). Not sure whether true or false.pdf
Random signal analysis question (19). Not sure whether true or false.pdfRandom signal analysis question (19). Not sure whether true or false.pdf
Random signal analysis question (19). Not sure whether true or false.pdf
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 

Will th ebelow code work andif not please help me fix it. Basically .pdf

  • 1. Will th ebelow code work andif not please help me fix it. Basically I am taking in a line of code and we are supposed to use fail state to figure out which kind of format the line will follow. It will either follow one of two formats. So I am trying to say if while reading in it hits something that doesn't work it must be the OTHER kind of line. Am I using clear and fail functions correctly? It is important that when it fails the next value being read in goes into the place where it failed reading in. So if it tries to read something in and it fails the next value read in should go into THAT value and not the next one. Solution Reasons: i) You cannot start read vertexOne or vertexTwo, before you open the stream ii) Set up your file reading in streams based on the layout of your files, so what you can do is to have if-else statements that select the right stream setup bases on the filname. Program: #include "Triangle.h" #include "Graphics.h" #include "Shape.h" #include using namespace std; Triangle::Triangle() { } Triangle::Triangle(Point pt1, Point pt2, Point pt3, Color color) { vertexOne = pt1; vertexTwo = pt2; vertexThree = pt3; vertexOneColor = color; vertexTwoColor = color; vertexThreeColor = color; } Triangle::Triangle(Point pt1, Color col1, Point pt2, Color col2, Point pt3, Color col3)
  • 2. { vertexOne = pt1; vertexOneColor = col1; vertexTwo = pt2; vertexTwoColor = col2; vertexThree = pt3; vertexThreeColor = col3; } void Triangle::setColor(Color col) { vertexOneColor = col; vertexTwoColor = col; vertexThreeColor = col; } void Triangle::setVertexOne(Point pt) { vertexOne = pt; } void Triangle::setVertexTwo(Point pt) { vertexTwo = pt; } void Triangle::setVertexThree(Point pt) { vertexThree = pt; } Point Triangle::getVertexOne() { return vertexOne; } Point Triangle::getVertexTwo() { return vertexTwo; } Point Triangle::getVertexThree() {
  • 3. return vertexThree; } void Triangle::setVertexOneColor(Color col) { vertexOneColor = col; } void Triangle::setVertexTwoColor(Color col) { vertexTwoColor = col; } void Triangle::setVertexThreeColor(Color col) { vertexThreeColor = col; } Color Triangle::getVertexOneColor() { return vertexOneColor; } Color Triangle::getVertexTwoColor() { return vertexTwoColor; } Color Triangle::getVertexThreeColor() { return vertexThreeColor; } void Triangle::read(istream& ins) { // These are values of the each vertex and color Point vertex1; Point vertex2; Point vertex3; Color col; Color vertex1Color; Color vertex2Color; Color vertex3Color;
  • 4. ins >> vertex1 >> vertex1Color >> vertex2 >> vertex2Color >> vertex3; // Checks whether ins has entered a fail state of not if (ins.fail()) { ins.clear(); Triangle(vertex1, vertex2, vertex3, vertex1Color); } else { ins >> vertex3Color; Triangle(vertex1, vertex1Color, vertex2, vertex2Color,vertex3, vertex3Color); } } void Triangle::write(ostream& outs) { Point out_vertex1 = getVertexOne(); Point out_vertex2 = getVertexTwo(); Point out_vertex3 = getVertexThree(); Color out_vertex1Color = getVertexOneColor(); Color out_vertex2Color = getVertexTwoColor(); Color out_vertex3Color = getVertexThreeColor(); outs << out_vertex1 << " " << out_vertex1Color << " " << out_vertex2 << " " << out_vertex2Color << " " << out_vertex3 << " " << out_vertex3Color; } istream& operator >> (istream& ins, Triangle& tri) { tri.read(ins); return ins; } ostream& operator << (ostream& outs, Triangle tri) { tri.write(outs); return outs; }
  • 5. void Triangle::draw (Graphics& drawer) { int xa = checkRange(getVertexOne().getX()); int ya = checkRange(getVertexOne().getY()); int xb = checkRange(getVertexTwo().getX()); int yb = checkRange(getVertexTwo().getY()); int xc = checkRange(getVertexThree().getX()); int yc = checkRange(getVertexThree().getY()); float red1 = (float)(getVertexOneColor().getRed()/255.0); float green1 = (float)(getVertexOneColor().getGreen()/255.0); float blue1 = (float)(getVertexOneColor().getBlue()/255.0); float red2 = (float)(getVertexTwoColor().getRed()/255.0); float green2 = (float)(getVertexTwoColor().getGreen()/255.0); float blue2 = (float)(getVertexTwoColor().getBlue()/255.0); float red3 = (float)(getVertexThreeColor().getRed()/255.0); float green3 = (float)(getVertexThreeColor().getGreen()/255.0); float blue3 = (float)(getVertexThreeColor().getBlue()/255.0); float a01, a02, a03, b01, b02, b03, c01, c02, c03, beta1, beta2, beta3; float lowX = 0, lowY = 0, highX = 0, highY = 0, i, j, R, G, B, t1, t2, t3; float triangleArea = 0; a01 = (float)(ya - yb); a02 = (float)(ya - yc); a03 = (float)(yb - yc); b01 = (float)(xb - xa); b02 = (float)(xc - xa); b03 = (float)(xc - xb); c01 = -(a01 * (xa+xb)+ b01 * (ya + yb)) / 2; c02 = -(a02 *(xa+xc) + b02 * (ya + yc)) / 2; c03 = -(a03 *(xb+xc) + b03 * (yb + yc)) / 2; if (evalFunc(xc,yc, (int)a01, (int)b01, (int)c01) < 0) { a01 = a01 * (-1); b01 = b01 * (-1); c01 = c01 * (-1);
  • 6. } if (evalFunc(xb,yb, (int)a02, (int)b02, (int)c02) < 0) { a02 = a02 * (-1); b02 = b02 * (-1); c02 = c02 * (-1); } if (evalFunc(xa,ya, (int)a03, (int)b03, (int)c03) < 0) { a03 = a03 * (-1); b03 = b03 * (-1); c03 = c03 * (-1); } if (xa > xb) { highX = (float)xa; } else { highX = (float)xb; } if (xc > highX) { highX = (float)xc; } if (ya > yb) { highY = (float)ya; } else { highY = (float)yb; } if (yc > highY) { highY = (float)yc;
  • 7. } if (xa < xb) { lowX = (float)xa; } else { lowX = (float)xb; } if (xc < lowX) { lowX = (float)xc; } if (ya < yb) { lowY = (float)ya; } else { lowY = (float)yb; } if (yc < lowY) { lowY = (float)yc; } triangleArea = triArea(xa, ya, xb, yb, xc, yc); for (i = lowX; i < (highX+1); i++) { for (j = lowY; j < (highY+1); j++) { t1 = (float)evalFunc((int)i,(int)j, (int)a01, (int)b01, (int)c01); t2 = (float)evalFunc((int)i,(int)j, (int)a02, (int)b02, (int)c02); t3 = (float)evalFunc((int)i,(int)j, (int)a03, (int)b03, (int)c03); if ((t1 >= 0)&&(t2 >= 0)&&(t3 >= 0)){ t1 = triArea(xb, yb, xc, yc, (int)i, (int)j); t2 = triArea(xc, yc, xa, ya, (int)i, (int)j);
  • 8. t3 = triArea(xa, ya, xb, yb, (int)i, (int)j); beta1 = triArea(xb, yb, xc, yc, (int)i, (int)j)/triangleArea; beta2 = triArea(xc, yc, xa, ya, (int)i, (int)j)/triangleArea; beta3 = triArea(xa, ya, xb, yb, (int)i, (int)j)/triangleArea; R = (beta1*red1 + beta2*red2 + beta3*red3) * 255; G = (beta1*green1 + beta2*green2 + beta3*green3) * 255; B = (beta1*blue1 + beta2*blue2 + beta3*blue3) * 255; drawer.setPixel((int)i,(int)j,Color((int)R,(int)G,int(B))); } } } } int Triangle::checkRange(int val) { if (val < 0) return 0; else if (val > DIMENSION) return DIMENSION; else return val; } int Triangle::evalFunc(int p, int q, int a, int b, int c) { int e = a*p+b*q+c; return(e); } float Triangle::triArea(int xa, int ya, int xb, int yb, int xref, int yref) { xa -= xref; xb -= xref; ya -= yref; yb -= yref; return((float)(sqrt(pow((double)(yb*xa)-(xb*ya), (double)2))*0.5)); }