Hey I am having trouble with this problem in C++:
The first race is tomorrow! You are provided a list of race entries in the following form:
vector<string> entryList = { "42, Vance Cardoza",
"55, Vanessa Pandara",
"36, Gaston Carlton",
"99, Rich Diesel",
"10, Euler Bustamente" };
In your main() function instantiate a Race object.
Use a C++ iterator to walk through the entries in the list above, parse out each car number and driver name and add them to the Race object using the AddRaceCar method.
My code so far:
#pragma once
#include <string>
#include <algorithm>
#include<iterator>
#include<vector>
#include <iostream>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
class Car
{
public:
Car();
~Car();
string Make;
string Model;
int Year;
string Color;
float AverageMileage;
void FillErUp(unsigned int gallons);
float GetRemainingFuel();
float GetSpeed();
float SetSpeed(float newSpeed);
private:
float fuelTankCapacity;
float fuelLevel;
float speed;
};
class RaceCar : public Car{
public:
RaceCar CreateRacer(int CNumber, string DName) {
RaceCar();
~RaceCar();
int RaceCarNumber(int* x);
string DriverName(string* x);
}
};
class Race{
protected:
vector<RaceCar>cars;
public:
RaceCar * AddRaceCar(int RCNumber, string DrivName){
RaceCar *car;
DriverName *name;
}
public:
int& GetCarByNumber(int RCNumber){
return &RaceCarNumber;
}
public:
string PrintResults(int& finOrder, int& RCNumber) {
GetCarByNumber(*RaceCarNumber);
vector <int> finishOrder;
return cout << "The result of the race is: " <<
finishOrder + RaceCarNumber;
}
};
int main(){
int i;
vector <RaceCar> cars;
Race BigRace;
Car RaceCar;
vector<string> entryList = { "42, Vance Cardoza",
"55, Vanessa Pandara",
"36, Gaston Carlton",
"99, Rich Diesel",
"10, Euler Bustamente" };
for (int i = 0, j = 0; i < entryList.size(); i++)
{
if (entryList.at(i) == ',') //not sure why compiler is unable to
identify ==
{
(entryList.at(i) = '(\0)');
cars.push_back(entryList.substr(j, i - j)); //pushing the sub
string to int
j = i + 1;
}
}
}
vector<int> finishOrder = { 55, 99, 42, 10, 36 };
string PrintResults(finishOrder, cars);
}
please let me know what I need to change (pointers most likely) in order for it to compile / at least technically solve that part of the problem.
Hi. Although the question is not entirely clear, I believe the
following main function is what it is asking for.
If this was a homework question where some of the code was
provided, it does make sense as to why it doesn't compile. It is
because many functions are either abstract or undefined. The
following code gives the required main function asked in the
original question:
#include <string>
#include <algorithm>
#include<iterator>
#include<vector>
#include <iostream>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
using namespace std;
class Car
{
public:
// Car();
// ~Car();
string Make;
string Model;
int Year;
string Color;
float AverageMileage;
void FillErUp(unsigned int gallons);
float GetRemainingFuel();
float GetSpeed();
float SetSpeed(float newSpeed);
private:
float fuelTankCapacity;
float fuelLevel;
float speed;
};
class RaceCar : public Car
{
public:
int CarNumber;
string DriverName;
// RaceCar();
// ~RaceCar();
void CreateRacer(int CNumber, string DName)
{
// int RaceCarNumber(int* x);
// string DriverName(string*
x);
CarNumber = CNumber;
DriverName = DName;
}
};
class Race
{
protected:
vector<RaceCar> cars;
public:
RaceCar * AddRaceCar(int RCNumber, string
DrivName)
{
RaceCar *car;
car->CreateRacer(RCNumber,
DrivName);
cars.push_back(*car);
return car;
}
// int& GetCarByNumber(int RCNumber)
// {
// return &RCNumber;
// }
// string PrintResults(int& finOrder, int&
RCNumber)
// {
// GetCarByNumber(*RaceCarNumber);
// vector <int> finishOrder;
// return cout << "The result of
the race is: " << finishOrder + RaceCarNumber;
// }
};
int main()
{
int i;
vector<RaceCar> cars;
Race BigRace;
Car RaceCar;
vector<string> entryList = { "42, Vance
Cardoza",
"55, Vanessa Pandara",
"36, Gaston Carlton",
"99, Rich Diesel",
"10, Euler Bustamente" };
for (int j = 0; j < entryList.size(); j++)
{
for( int i = 0; i <
entryList.at(j).size(); i++)
{
//
cout<<entryList.at(i)[4];
if
(entryList.at(j)[i] == ',') //not sure why compiler is unable to
identify ==
{
// (entryList.at(i) = '\0';
BigRace.AddRaceCar(stoi(entryList.at(j).substr(0,
i)),entryList.at(j).substr(i+1, entryList.at(j).size()));
}
}
}
// vector<int> finishOrder = { 55, 99, 42,
10, 36 };
// string PrintResults(finishOrder, cars);
}
Please comment if any more clarification is required.
Hey I am having trouble with this problem in C++: The first race is tomorrow! You...
Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...
C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...
Hi, I have C++ programming problem here:
Problem:
Please modify your string type vector in for push_back()
function as below:
void push_back(string str)
{
// increase vector size by one
// initialize the new element with str
}
In addition, the standard library vector doesn't provide
push_front(). Implement
push_front() for your vector. Test your code with the main function
below.
int main()
{
vector v1(3);
cout<<"v1: ";
v1.print(); // this should display -, -, -
for...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false;...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false; } for...
In C++ I am trying to implement a log base 2 hash table utilizing the shift function. So, the code determines the position of where the value will be stored using log2. But am having issues using the shift part as everything just wants to pile on to zero. //ChainingHash - log2 #include<iostream> #include<vector> #include<iterator> #include<string> #include<cmath> using namespace std; #define BUCKET 10 //no. of buckets class Hash { vector<int>*table; //ptr containing buckets public: Hash();...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
C++: Need help debugging my code
I am writing this and using some other examples as reference code
while rewriting it with my own understanding of the material but am
having trouble making it finally compile. Below is a picture of the
error messages.
//main.cpp
//Semester Project
//Created by J---on 5/6/2019
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
void instructions(); //displays program details and
instructions
void openFile();
void takeInput(int*);
void switchBoard(int*);
struct price
{...
I am having problems with the following assignment. It is done
in the c language. The code is not reading the a.txt file. The
instructions are in the picture below and so is my code. It should
read the a.txt file and print. The red car hit the blue car and
name how many times those words appeared. Can i please get some
help. Thank you.
MY CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char *str;
int...