正在加载图片...
2.FileDraw(30)In this problem you write a program which draws Circles and Rectangle on screen,where the location,size,color and density of the Circles and Rectangles are read from a file.Suppose,for example,the following data is read: rectangle:5.993125.178617.332375.65564 Yellow0.5 circle:6.970141.561510.3273260 range0.8 rectangle:0.6079843.196931.348073.51565Gold0.3 The file will always consist of zero or more lines,where each line starts with either “circle'”or“rectangle''.The“circle”will be followed by the center of the circle, followed by the radius of the circle and its fill color and density.The "rectangle"will always be followed by the lower-left and upper-right points of the rectangle with each point represented by x and y coordinates.Assume that the program always reads a file named shapes.txt.You may also assume that all numeric values given will be doubles. For the test purpose,we have implement the main function for you.All you need is to write a function called readAndDraw (ifstream &inFile) int main (int argc,char *argv[]) r ifstream inFile (argc =2 argv[1]"shapes.txt"); readAndDraw (inFile,outFile); inFile.close O return O; } void readAndDraw ifstream &inFile double x,y,r,x1,y1,density; string shape,color; bool quit false; while (!quit &!inFile.eof () inFile >shape; if (shape ="circle:" L inFile >>x>>y>>r>>color >density; MyArcT circle (x,y,r,color,density); circle.draw () else if (shape =="rectangle:" inFile >>x>>y>>x1>>y1 >color >density; MyRectangleT rect(x,y,x1,y1,color,density); rect.draw(); else quit true;2. FileDraw (30) In this problem you write a program which draws Circles and Rectangle on screen, where the location, size, color and density of the Circles and Rectangles are read from a file. Suppose, for example, the following data is read: rectangle: 5.99312 5.17861 7.33237 5.65564 Yellow 0.5 circle: 6.97014 1.56151 0.327326 Orange 0.8 rectangle: 0.607984 3.19693 1.34807 3.51565 Gold 0.3 The file will always consist of zero or more lines, where each line starts with either “circle” or “rectangle”. The “circle” will be followed by the center of the circle, followed by the radius of the circle and its fill color and density. The “rectangle” will always be followed by the lower-left and upper-right points of the rectangle with each point represented by x and y coordinates. Assume that the program always reads a file named shapes.txt. You may also assume that all numeric values given will be doubles. For the test purpose, we have implement the main function for you. All you need is to write a function called readAndDraw (ifstream &inFile) int main (int argc, char *argv[]) { ifstream inFile (argc == 2 ? argv[1] : "shapes.txt"); readAndDraw (inFile, outFile); inFile.close (); return 0; } void readAndDraw ( ifstream &inFile ) { double x, y, r, x1, y1, density; string shape, color; bool quit = false; while (!quit && !inFile.eof ()) { inFile >> shape; if (shape == "circle:") { inFile >> x >> y >> r >> color >> density; MyArcT circle (x, y, r, color, density); circle.draw (); } else if (shape == "rectangle:") { inFile >> x >> y >> x1 >> y1 >> color >> density; MyRectangleT rect (x, y, x1, y1, color, density); rect.draw (); } else { quit = true; } } }
<<向上翻页
©2008-现在 cucdc.com 高等教育资讯网 版权所有