Convert everything to STL: #include <iostream> #include <cmath> #include <math.h
ID: 3544967 • Letter: C
Question
Convert everything to STL:
#include <iostream>
#include <cmath>
#include <math.h>
#include <conio.h>
#include <vector>
#include <string>
using namespace std;
//Class point definition
class point {
//overloading constructor
public:
double x, y;
point(); //default constructor
//point(const point &a); //copy constructor
//~point(); //desctructor
//overloading operator- : distance between two points
double operator-(point &op2);
void displaypoint();
void inputpoint();
void setpoint(double a, double b);
point getpoint();
// Overloading operator = for point instance assignment
//point operator = (point & a);
friend ostream& operator << (ostream&, point&);
};
void point::setpoint(double a, double b)
{
x=a;
y=b;
}
// Overloading operator << for point printing
ostream & operator <<(ostream & out, point &z){out<<z.x<<" "<<z.y; return out;}
//Class shape definition
class shape {
protected:
vector<point> corners;
string label;
public:
shape();//default constructor
//shape(const shape &a); //copy constructor
//virtual ~shape(); //desctructor
//The following are all pure virtual member funtions
virtual double area() = 0;
virtual double perimeter() = 0;
//virtual void center() = 0;
virtual void inputcorners() = 0;
virtual void showcorners() = 0;
};
class triangle : public shape
{
protected:
double side1, side2, side3;
double angle1, angle2, angle3;
public:
triangle(); //default constructor
//copy constructor
triangle(const triangle &t);
// ~triangle();
virtual double area();
virtual double perimeter();
//virtual void center();
virtual void inputcorners();
virtual void showcorners();
void modify_pt();
double base();
double height();
bool isright();
bool isisosceles();
bool isequilateral();
bool isacute();
bool isobtuse();
void computesides();
void computeangles();
//Overloading operator = for triangle instance assignment
triangle operator= (triangle & a);
};
void triangle::inputcorners()
{
double a,b;
point p1, p2, p3;
cin>>a>>b;
p1.setpoint(a,b);
cin>>a>>b;
p2.setpoint(a,b);
cin>>a>>b;
p3.setpoint(a,b);
corners[0]=p1;
corners[1]=p2;
corners[2]=p3;
}
int main()
{
triangle t1, t2;
t1. inputcorners();
t2. inputcorners();
t1.showcorners();
t2.showcorners();
cout<<"area:"<<t1.area()<<" "<<t2.area();
cout<<"perimeter:"<<t1.perimeter()<<" "<<t2.perimeter();
getchar();
getchar();
}
point ::point(){
x=0;
y=0;
}
triangle::triangle()
{
corners.resize(3);
}
shape::shape()
{
}
double triangle::area()
{
//double area=base()*height()/2;
point a=corners[0],b=corners[1],c=corners[2];
double d1=sqrt(((b.x-a.x)*(b.x-a.x))+(a.y-b.y)*(a.y-b.y));
double d2=sqrt(((b.x-c.x)*(b.x-c.x))+(c.y-b.y)*(c.y-b.y));
double d3=sqrt(((c.x-a.x)*(c.x-a.x))+(a.y-c.y)*(a.y-c.y));
double s=(d1+d2+d3)/2;
double area=sqrt(s*(s-d1)*(s-d2)*(s-d3));
return area;
}
double triangle::base()
{
point a=corners[0];
point b=corners[1];
point c=corners[2];
double d=sqrt(((b.x-a.x)*(b.x-a.x))+(a.y-b.y)*(a.y-b.y));
return d;
}
double triangle::perimeter()
{
point a=corners[0],b=corners[1],c=corners[2];
double d1=sqrt(((b.x-a.x)*(b.x-a.x))+(a.y-b.y)*(a.y-b.y));
double d2=sqrt(((b.x-c.x)*(b.x-c.x))+(c.y-b.y)*(c.y-b.y));
double d3=sqrt(((c.x-a.x)*(c.x-a.x))+(a.y-c.y)*(a.y-c.y));
double perimeter=d1+d2+d3;
return perimeter;}
void triangle::showcorners()
{
point a=corners[0],b=corners[1],c=corners[2];
cout<<a<<b<<c;
}
Explanation / Answer
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
bool ListFiles(wstring path, wstring mask, vector<wstring>& files) {
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA ffd;
wstring spec;
stack<wstring> directories;
directories.push(path);
files.clear();
while (!directories.empty()) {
path = directories.top();
spec = path + L"\" + mask;
directories.pop();
hFind = FindFirstFile(spec.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
return false;
}
do {
if (wcscmp(ffd.cFileName, L".") != 0 &&
wcscmp(ffd.cFileName, L"..") != 0) {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
directories.push(path + L"\" + ffd.cFileName);
}
else {
files.push_back(path + L"\" + ffd.cFileName);
}
}
} while (FindNextFile(hFind, &ffd) != 0);
if (GetLastError() != ERROR_NO_MORE_FILES) {
FindClose(hFind);
return false;
}
FindClose(hFind);
hFind = INVALID_HANDLE_VALUE;
}
return true;
}
int main(int argc, char* argv[])
{
vector<wstring> files;
if (ListFiles(L"F:\cvsrepos", L"*", files)) {
for (vector<wstring>::iterator it = files.begin();
it != files.end();
++it) {
wcout << it->c_str() << endl;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.