Question

In: Computer Science

C++In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must...

C++

In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine a class already defined by a classmate. Use proper C++ syntax to present your class.

Solutions

Expert Solution

C++ PROGRAM:

OUTPUT SNAPSHOTS:

TEXT CODE:

#include
using namespace std;
// Book Class
class Book{
// A Book can have its Name, Author and Number of Pages has its attributes.
private:
string name;
string author;
int numberOfPages;
  
public:
// Getter Function for name
string getName(){
return name;
}
// Getter Function for author
string getAuthor(){
return author;
}
// Getter Function for numberOfPages
int getNumberOfPages(){
return numberOfPages;
}
  
// Setter Function for name
void setName(string n){
name = n;
}
// Setter Function for author
void setAuthor(string a){
author = a;
}
// Setter Function for numberOfPages
void setNumberOfPages(int pages){
numberOfPages = pages;
}
  
// Function to check if the book is popular or not by its name
bool IsBookPopular(string nameOfBook){
if(nameOfBook=="C++ Primer" ||
nameOfBook=="Effective C++" ||
nameOfBook=="A Tour of C++"){
return true;
} else {
return false;
}
}
// Function to decide the Book size by the number of pages in it
string BookSize(int pages){
if(pages<100){
return "Thin";
} else if(pages>=100 && pages< 300) {
return "Medium";
} else {
return "Thick";
}
}
// Function to check if the book author is famour of not
bool IsBookAuthorFamous(string author){
if(author=="Bjarne Stroustrup" ||
author=="Greg Perry" ||
author=="Brian Kernighan"){
return true;
} else {
return false;
}
}
};

int main()
{
// Creating the Book object
Book b1;
// Setting the values using Book Class object and its setter function
b1.setName("Effective C++");
b1.setAuthor("Bjarne Stroustrup");
b1.setNumberOfPages(400);
  
// Checking the Behavior of the Book
if(b1.IsBookPopular(b1.getName()) == true){
cout << "Book is Popular!" << endl;
} else {
cout << "Book is Not Popular!" << endl;
}
if(b1.IsBookAuthorFamous(b1.getAuthor()) == true){
cout << "Book Author is Famous!" << endl;
} else {
cout << "Book Author is Not Famous!" << endl;
}
cout << "Book size is " << b1.BookSize(b1.getNumberOfPages()) << endl;
  
return 0;
}

EXPLANATION:

  • In the sample program, Book is taken as the class, which has three attributes, that is name, author and numberOfPages.
  • In the class definition, Getter and Setter function are defined.
  • For the checking the behavior of the Book, three function are developed namely IsBookPopular(), IsBookAuthorFamous() and BookSize().
  • The IsBookPopular() method checks whether the book is popular or not.
  • The IsBookAuthorFamous() method checks whether the book author is famous or not.
  • The BookSize() method decides the size of the book based on the number of pages in it.
  • For the abstraction of the class attributes, they are declared as the private and their values are set using setter function from the main() function,

Related Solutions

In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must quickly...
In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs....
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts a false....
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns. I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
Briefly explain the terms used in object-oriented programming with examples.
Briefly explain the terms used in object-oriented programming with examples.
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
We now begin learningconcept in modern programming - Object Orientation Programming (OOP). Let's write our first...
We now begin learningconcept in modern programming - Object Orientation Programming (OOP). Let's write our first Class definition, and then instantiate an object of this Class to run in a test application to test our objects behaviors. Employee.java - Make an Employee Class, code to the design of the UML diagram -name: String -employeeId: int -Shift: Boolean -HourlyPay: double +Employee() +setName(n: String) +setemployeeId(i:int) +setShift(s:Boolean) +setHourlyPay(p:double) +getname() : String +getemployeeId() : int +getShift() : Boolean +getHourlyPay() : double +calculateOvertimePay( hours :...
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities....
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities. Group of answer choices A. True B. False 2. __________ programming is centered on the procedures or actions that take place in a program. Group of answer choices A. Class B. Object-oriented C. Menu-driven D. Procedural/ Structural 3. __________ programming encapsulates data and functions in an object. Group of answer choices A. Object-oriented B. Class C. Menu-driven D. Procedural 4. The data in an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT