Question
I need this code to work and translated to C++ can anyone help me //.h file code: #include #include #include #include exceptionhelper.h //.h file code:
I need this code to work and translated to C++ can anyone help me
//.h file code:
#include
//.h file code:
#include
#include
public: public: std::wstring toString(); };
//exception for invalid year in publishYear class InvalidPublishYearException extends Exception { private: private: int year = 0; public: public: InvalidPublishYearException(int year); Override std::wstring toString(); };
class Book { private: private: std::wstring name; std::wstring author; int publishYear = 0; int pages = 0; //constructor public: public: Book(const std::wstring & name, const std::wstring & author, int publishYear, int pages);
//getters for variables std::wstring getName(); std::wstring getAuthor(); int getPublishYear(); int getPages();
static void main(std::vector
//Helper class added by C# to C++ Converter:
#include
public: private class EmptyStringException | InvalidPublishYearException : public std::exception { private: private: std::string msg;
public: public: private: EmptyStringException | *InvalidPublishYearException(const std::string & *message = L"");
//C# TO C++ CONVERTER TODO TASK: Methods returning tuples are not converted by C# to C++ Converter: // const char * what() const throw() // { // return msg.c_str(); // } };
//.cpp file code:
#include "snippet.h"
private: std::wstring EmptyStringException::toString();
private *InvalidPublishYearException::InvalidPublishYearException(int year);
Override std::wstring InvalidPublishYearException::toString();
private *Book::Book(const std::wstring & *name, const std::wstring & *author, int publishYear, int pages);
std::wstring Book::getName();
std::wstring Book::getAuthor();
int Book::getPublishYear();
int Book::getPages();
void Book::main(std::vector &
//Helper class added by C# to C++ Converter:
#include
class const EmptyStringException | InvalidPublishYearException & : public std::exception { private: std::string msg;
public: const EmptyStringException | InvalidPublishYearException &(const std::string& message = "") : msg(message) { }
const char * what() const throw() { return msg.c_str(); } };
//.cpp file code:
#include "snippet.h"
EmptyStringException | *Book::EmptyStringException::InvalidPublishYearException(const std::string & *message) { }
std::wstring Book::EmptyStringException::toString() { //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: return (LL"Invalid Input : Empty String"); }
private *Book::InvalidPublishYearException::InvalidPublishYearException(int year) { this-> *year = year; }
Override std::wstring Book::InvalidPublishYearException::toString() { //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: return (LL"Invalid Publish Year : " + std::to_wstring(year) + LL"(less than 1900)"); }
private *Book::Book::Book(const std::wstring & *name, const std::wstring & *author, int publishYear, int pages) { //check if name is Empty if (name::isEmpty()) { throw EmptyStringException(); } //check if author is Empty if (author::isEmpty()) { throw EmptyStringException(); } //check if publishYear is less than 1900 if (publishYear < 1900) { throw InvalidPublishYearException(publishYear); } this-> *author = author; this-> *name = name; this-> *publishYear = publishYear; this-> *pages = pages; //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: System::out::println(LL"Successfully Created!"); }
std::wstring Book::Book::getName() { return name; }
std::wstring Book::Book::getAuthor() { return author; }
int Book::Book::getPublishYear() { return publishYear; }
int Book::Book::getPages() { return pages; }
void Book::Book::main(std::vector &
delete_Keyword *book; } catch (const const EmptyStringException | InvalidPublishYearException & &e) { System::out::println(e); }
delete_Keyword *scan; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started