Starting from:

$35

COSC6000 Homework 09 Solved

Develop a class called BaseballPark that stores Baseball Parks data

Your class will have at least five member variables. (must be private) type std::string to represent the franchise.

 type std::string to represent the name of stadium. type std::string to represent the name of city. type int to represent the capacity.

type USLength to represent the center field dimension.

You have developed USLength class in HW7.

The complete class will include all the following member functions:

a constructor to set a franchise, stadium, city, capacity and center field dimension as 

 BaseballPark park(franchise, stadium, city, capacity, centerField); a default constructor (takes no input) that sets name=”NA”, and default number (maybe 0).

Mutators for each member variable.

Accessors for each member variable.

Add “const” modifier for member function that does not modify member variables.

 Develop C++ code to process following tasks:

Reads “MajorLeagueBallparks.csv” and store those in an array.

Download the file from here. 

How to read CSV (Comma­Separated Values) file in C++? See below or see here

(http://www.cplusplus.com/forum/general/13087/) .

Use your BaseballPark class to recored data.

 Use std::vector container class to store all data in an array.

Your vector type must be like:

 

#include "USLength.h" 

 

class BaseballPark{ public: 

    BaseballPark(); 

    BaseballPark(std::string franchise,std::string stadium,std::string city,int capacity,USLength cente rField); 

     

    /// member/friend functions 

     private:     std::string franchise;     std::string stadium;     std::string city;     int capacity; 

    USLength centerField; // you may need your namespace 

}; 

 

/// 

/// your code here 

///  

int main(int argc, const char * argv[]) { 

     

    // YOUR code here 

     

    std::ifstream infile; 

    infile.open("MajorLeagueBallparks.csv");// Path to the CSV file     if (infile.fail()){ 

        std::cout << "file not found\n";         return -1; 

    } 

    std::string franchise;     std::string stadium;     std::string city;     int capacity;     int yards;     int feet; 

    std::string entry; 

     

    std::string line; 

    while (std::getline(infile,line)){         std::stringstream ststrm(line);         std::getline(ststrm,franchise,',');         std::getline(ststrm,stadium,',');         std::getline(ststrm,city,',');         std::getline(ststrm,entry,',');         capacity = std::stoi(entry);         std::getline(ststrm,entry,',');         yards = std::stoi(entry);         std::getline(ststrm,entry);         feet = std::stoi(entry); 

         

        USLength centerField(yards,feet,0);//you might need namespace 

        BaseballPark bbpark(franchise,stadium,city,capacity,centerField);         // YOUR code here 

 

 Upload your USLength class files as well as your code if you make some changes onUSLength class.

More products