Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #include "exceptionhelper.h"

//.h file code:

#include #include #include "exceptionhelper.h"

#include > class EmptyStringException extends Exception {

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 & args);

//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 & *args);

//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 & *args) { //creating object for Scanner class Scanner * scan = new Scanner(System::in); std::wstring name = Luniquetempvar, author = LL""; int year, pages; //Reading input //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: System::out::print(LL"Name :"); name = scan-> nextLine(); //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: System::out::print(LL"Author :"); author = scan-> nextLine(); //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: System::out::print(LL"Publish Year :"); year = scan-> nextInt(); //C# TO C++ CONVERTER TODO TASK: The following line could not be converted: System::out::print(LL"Number of Pages :"); pages = scan-> nextInt(); try { //creating object for Book Book * book = new Book(name, author, year, pages);

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions