Description
* The code must contain no more than 50,000 characters.
* Your code must NOT include any TAB character. Convert each TAB to 4 spaces before submitting.
* You are not allowed to copy any piece of code from the internet or from any other resource.
* You are not allowed to copy any piece of code from other students. * You are not allowed to include any files or built-in libraries, except for the described ones.
* Your coding style must follow exactly the coding style specified in
CodingStyle.pdf.
* Half the mark is dedicatd to comments explaining the code, test cases, and following CodingStyle.
To submit the code:
* Write your code in exactly one cpp text file such as myfile.cpp. * Make sure that myfile.cpp contains the actual code, for example open it in Notepad (do not confuse it with cbp file).
* Encode the file using the assign_encoder tool as the following: g++ -O3 -o assign_encoder.exe assign_encoder.cpp
assign_encoder.exe ./myfile.cpp 2 3 20101111 20102222 20113333 * The 2 in the above line is the assignment ID. The 3 in the above line is number of students.
* Submit the resulting assign_2_20101111_20102222_20113333.bin file and do not submit the original myfile.cpp.
* Do not change the name of the resulting file.
* Do not compress the resulting file. Just send it exactly as it is. * Write a C++ code that does the following:
* You are not allowed to use any built-in functions except: <cmath>,
<cstdlib>, <cstdio>, <cstring>, <iostream>.
* You are not allowed to use string class, vector, or anything from STL libraries.
* Implement base struct Shape and derived struct Circle, Rectangle and Ellipse simulating polymorphism without using the virtual keyword. Do not use the C++ inheritance or polymorphism mechanisms but simulate them as described in our lecture Lecture05_GenericProg. You are allowed to use some lecture code. Your code must be general.
* Write standard C++, such that the following main() works. You are not allowed to modify the main().
* Half the mark is dedicatd to comments explaining the code before each code line, test cases, and following the CodingStyle.pdf file.
int main()
{
Circle circle;
CircleInitialize(&circle, 10); // circle with radius 10
Rectangle rectangle;
RectangleInitialize(&rectangle, 3, 5); // rectangle with width 3 and height 5
Ellipse ellipse;
EllipseInitialize(&ellipse, 10, 12); // ellipse with radius 10, 12 Shape* shapes[3]; shapes[0]=(Shape*)&circle ; shapes[1]=(Shape*)&rectangle ; shapes[2]=(Shape*)&ellipse ; double total_area=0; int i; for(i=0;i<3;i++)
{
double d=GetArea(shapes[i]);
total_area+=d;
PrintInfo(shapes[i]); // prints (cout) the radius if circle, width and height if rectangle, … etc
}
cout<<total_area<<endl; // check if the value is correct return 0;
}
Reviews
There are no reviews yet.