Robot.cpp
unknown
c_cpp
4 years ago
3.4 kB
7
Indexable
#define _CRT_SECURE_NO_WARNINGS
#include "Robot.h"
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
sdds::Robot::Robot() {
this->name = new char[25];
this->location = new char[25];
strcpy(this->name, "");
strcpy(this->location, "");
this->height = 0;
this->width = 0;
this->speed = 0;
this->weight = 0;
this->deployed = false;
}
sdds::Robot::Robot(const char* name, const char* location, double weight, double width, double height, double speed, bool deployed) {
this->name = new char[25];
this->location = new char[25];
strcpy(this->name, name);
strcpy(this->location, location);
this->height = height;
this->weight = weight;
this->width = width;
this->speed = speed;
this->deployed = deployed;
}
sdds::Robot::~Robot() {
}
sdds::Robot sdds::Robot::set(const char* name, const char* location, double weight, double width, double height, double speed, bool deployed) {
strcpy(this->name, name);
strcpy(this->location, location);
this->height = height;
this->weight = weight;
this->width = width;
this->speed = speed;
this->deployed = deployed;
return *this;
}
void sdds::Robot::setLocation(char* location) {
strcpy(this->location, location);
}
void sdds::Robot::setDeployed(bool deployed) {
this->deployed = deployed;
}
char* sdds::Robot::getName() {
return name;
}
char* sdds::Robot::getLocation() {
return location;
}
bool sdds::Robot::isDeployed() {
return deployed;
}
bool sdds::Robot::isValid() {
if (_strcmpi(name, "Broken") == 0 || _strcmpi(name,"")==0) {
return false;
}
else {
return true;
}
}
double sdds::Robot::getSpeed() {
return speed;
}
void sdds::Robot::display() {
cout <<fixed<<setprecision(1)<< "|" << name << right << setw(20) << "|" << location << setw(20) << "|" << weight << setw(20) << "|" << width << setw(20) << "|" << height << setw(20) << "|" << speed;
if (deployed) {
cout << right << setw(20) << "|" << "YES" << endl;
}
else {
cout << right << setw(20) << "|" << "NO" << endl;
}
}
int conrtolRooomReport(sdds::Robot robot[], int num_robots)
{
int counter = 0;
double fastest = -2147483647;
int fastIndex = 0;
cout <<" ------- Robot Control Room-------"<< endl;
cout << setw(25) << right << " ---------------------------------------------------" << endl;
cout << "| ROBOT ID " << right << setw(20) << "| Location " << setw(20) << "| Weight " << setw(20) << "| Width " << setw(20) << "| Height " << setw(20) << "| Speed " << setw(20) << "| Deployed "<<setw(20)<<"|" << endl;
for (int i = 0; i < num_robots; i++) {
if (robot[i].isValid()) {
robot[i].display();
if (robot[i].isDeployed()) {
counter++;
}
if (robot[i].getSpeed() > fastest) {
fastest = robot[i].getSpeed();
fastIndex = i;
}
}
else {
return i;
}
}
cout << "=======================================================================" << endl;
cout << "SUMMARY"<<endl;
cout << counter << " robots are deployed " << endl;
cout << "The fastest Robot is" << endl;
cout << "| ROBOT ID " << right << setw(20) << "| Location " << setw(20) << "| Weight " << setw(20) << "| Width " << setw(20) << "| Height " << setw(20) << "| Speed " << setw(20) << "| Deployed |" << endl;
robot[fastIndex].display();
return -1;
}
Editor is loading...