. Create an application to complete task. The program needs to do the following:
ID: 3876953 • Letter: #
Question
. Create an application to complete task. The program needs to do the following:
• Import space craft records from the roster file when the program opens (roster file is given, it's just names and coordinates)
• Allow the user to search the records to see the coordinates that a particular space craft has as well as the distance from (0, 0, 0)
• Allow the user to create a new space craft record • Allow the user to delete a space craft record
• Get a count of the space crafts in the fleet
• Go through all space craft records and display a brief record for each space craft (both in lexicographical order and in order by distance from (0, 0, 0))
• When the program exits via option 7, update the roster file.
What you will be responsible for You will create the following files:
• OrderedList.cpp: A set of functions for the OrderedList class. Note: writing the function searchReturnIndex is optional, but if you opt not to write or use that function, then the prototype must be removed or commented out of the header file.
• Makefile: The file which contains the recipe for creating a.out, the executable file that will run the program.
Further details about the program
The program is menu driven. The program reads a roster file the name of which the user types into the command line. After compiling the program, the program is run by using the following command: a.out [name of roster file]
The roster file will start with a line that contains the number of records. Each line thereafter contains the data for each space craft. Each record line contains the space craft’s name, then a tab, then the X coordinate, then a tab, then the Y coordinate, then a tab, then the Z coordinate. The coordinates are double floating point numbers.
Explanation / Answer
here is your OrderedList implementation : ----------------------->>>>>>>>>>>>>>
OrderedList.h : ------------------------>>>>>>>>>>>>>
#ifndef ORDEREDLIST_H
#define ORDEREDLIST_H
#include<fstream>
using namespace std;
struct node{
SpaceCraft *d;
struct node *next;
};
typedef struct node Node;
class OrderedList{
Node *head;
int length;
public:
~OrderedList();
OrderedList();
void insert(SpaceCraft *data);
SpaceCraft* search(string name);
int getLength();
void remove(string name);
void traverse();
void traverseByDistance();
void traverseOut(ofstream &g);
};
#endif
OrderedList.cpp : ---------------------->>>>>>>>>>>>>>
#include "OrderedList.h"
int OrderedList::getLength(){
return length;
}
OrderedList::OrderedList(){
}
SpaceCraft* OrderedList::search(string name){
Node *temp = head;
while(temp != NULL){
if(temp->d->name == name){
return temp->d;
}
temp = temp->next;
}
return NULL;
}
OrderedList::~OrderedList(){
delete[] head;
}
void OrderedList::remove(string name){
Node *temp = head;
Node *prev = NULL;
while(temp != NULL){
if(temp->d->name == name){
if(prev == NULL){
head = temp->next;
delete temp;
break;
}else{
prev->next = temp->next;
delete temp;
break;
}
}
prev = temp;
temp = temp->next;
}
}
void OrderedList::insert(SpaceCraft *data){
Node *temp = head;
Node *prev = NULL;
Node *tmp = new Node;
tmp->d = data;
tmp->next = NULL;
if(head == NULL){
head = tmp;
}else{
while(temp != NULL){
if(temp->d->name > name){
tmp->next = temp;
prev->next = tmp;
}
prev = temp;
temp = temp->next;
}
}
length++;
}
void OrderedList::traverse(){
Node *temp = head;
while(temp != NULL){
cout<<temp->d->toString();
if(temp->next != NULL){
cout<<" -> ";
}
temp = temp->next;
}
}
void OrderedList::traverseOut(ofstream &g){
Node *temp = head;
while(temp != NULL){
g<<temp->d->toString();
if(temp->next != NULL){
g<<" -> ";
}
temp = temp->next;
}
}
void OrderedList::traverseByDistance(){
double dist = -1;
double tdist = 0;
Node *temp = head;
for(int i = 0;i<length();i++){
temp = head;
tdist = 99999999999;
for(int j = 0;j<length();j++){
if(temp->d->distance() < tdist && temp->d->distance() > dist){
tdist = temp->d->distance();
}
temp = temp->next;
}
temp = head;
for(int j = 0;j<length;j++){
if(temp->d->distance() == tdist){
cout<<temp->d->toString();
if(i != length-1)
cout<<" -> ";
}
}
}
dist = tdist;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.