Concept explainers
What is the difference between a class and an instance of the class?
Class:
In object oriented programming, the concept of class is considered as an important feature.
- A class is a collection of data members and member functions, which are used to represent the overall structure of the project.
- The objects are created to access the data members and its functions of the class.
Explanation of Solution
Difference between class and instance of the class:
Some of the differences between class and instance of the class are as follows:
Class | Instance of the class |
A class is like a blueprint from which the object is created. | Instance of a class is called as an object. |
When a class is created, its memory space is not allocated. | After the creation of an instance for the class, memory space is allocated. |
Class is a logical entity. | Instance of the class is a physical entity. |
The definition for a class can be created only once. | The object can be created as many times as possible. |
Syntax: class Class_name { //class members } |
Syntax: Class_name object; |
Example Program for class and instance of a class:
//Include the required header files
#include<iostream>
#include<string>
using namespace std;
//class name
class Mobile
{
//Access specifier
public:
//Declare a variable
string mobile_name;
};
//Main Function
int main()
{
//create a first object for mobile
Mobile object1;
//Assign a string to the object
object1.mobile_name = "Samsung";
//print the name
cout << object1.mobile_name << endl;
//create a second object for mobile
Mobile object2;
//Assign a string to the object
object2.mobile_name = "Apple";
//print the name
cout << object2.mobile_name << endl;
}
Explanation:
- In the above program, inside a class “Mobile”, declare a variable named “mobile_name”.
- Inside a main function
- Create an object named “object1”.
- Access and assign a string “Samsung” to the data member.
- Print the string.
- Create an object named “object2”.
- Access and assign a string “Apple” to the data member.
- Print the string.
Samsung
Apple
Want to see more full solutions like this?
Chapter 13 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
Electric Circuits. (11th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Mechanics of Materials (10th Edition)
- Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2)…arrow_forwardFind the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(7): daily_sales[i] = float(input('Enter the sales for ' \ + day_of_week[i] + ': ')arrow_forwardFind the error: daily_sales = [0.0, 0,0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(7): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': ')arrow_forward
- Find the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(6): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': '))arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it and normalize it? Give two references with your answer.arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Consider that the database offline is not allowed since people are connected to it and personal data might be bridged and not secured. Provide three refernces with you answer.arrow_forward
- Should software manufacturers should be tolerant of the practice of software piracy in third-world countries to allow these countries an opportunity to move more quickly into the information age? Why or why not?arrow_forwardI would like to know about the features of Advanced Threat Protection (ATP), AMD-V, and domain name space (DNS).arrow_forwardPlease show the code for the Tikz figurearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning