AIIIQ1 - fout << "The...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <fstream> #include <cmath> using namespace std; class circle { private: float r; float x; float y; public: circle(float radius, float horiz, float vert); void write(ostream& out); bool intersect(const circle& other); void expand_by(float factor); void shift_by(float deltax, float deltay); }; int main() { circle a(2.0, 5.0, 4.0), b(2.0, 0.0, 0.0); ofstream fout("circle.out"); fout << "The circles "; a.write(fout); fout << " and "; b.write(fout); if(a.intersect(b)) fout << "\nintersect\n\n"; else fout << "\ndo not intersect\n\n"; b.shift_by(1.5, 1.5); fout << "The circles "; a.write(fout); fout << " and "; b.write(fout); if(a.intersect(b)) fout << "\nintersect\n\n"; else fout << "\ndo not intersect\n\n"; a.expand_by(2.0);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fout &lt;&lt; &quot;The circles &quot;; a.write(fout); fout &lt;&lt; &quot; and &quot;; b.write(fout); if(a.intersect(b)) fout &lt;&lt; &quot;\nintersect\n\n&quot;; else fout &lt;&lt; &quot;\ndo not intersect\n\n&quot;; fout.close(); system(&quot;notepad circle.out&quot;); return 0; } circle::circle(float radius, float horiz, float vert){ r=radius; x=horiz; y=vert; } void circle::write(ostream&amp; out){ out&lt;&lt;endl&lt;&lt;&quot;radius horizontal and vertical postions &quot;&lt;&lt;r&lt;&lt;&quot;,&quot;&lt;&lt;x&lt;&lt;&quot;,&quot;&lt;&lt;y&lt;&lt;endl; } bool circle::intersect(const circle&amp; other){ float c; c=(x-other.x)*(x-other.x)+(y-other.y)*(y-other.y); if(sqrt(c&lt;=(r+other.r))) return true; else return false; } void circle::expand_by(float factor){ r=r*factor; } void circle::shift_by(float deltax, float deltay){ x=x+deltax; y=y+deltay; }...
View Full Document

Page1 / 2

AIIIQ1 - fout &amp;amp;lt;&amp;amp;lt; &amp;amp;quot;The...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online