Friday, March 11, 2022

How To Create an Object in C++

 A simple program to demonstrate how to create and use objects in C++ programming language.

 I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

Thank you very much for your support.






Program Listing

#include <iostream>

 using namespace std;

class Person {       // The class
  public:             // Access specifier
    int age;        // Attribute (int variable)
    string persons_name;  // Attribute (string variable)
    string address;  // Attribute (string variable)
};

int main() {
  Person Male; // Create an Object

  cout << "\n\n";
  cout << "How To Create an Object in C++";
  cout << "\n\n";
  // Access attributes and set values
  Male.age = 43;
  Male.persons_name = "John Dela Cruz";
  Male.address = "Silay City, Negros Occidental";
  
  // Print attribute values
  cout << "Persons Name    : " << Male.persons_name << "\n";
  cout << "Persons Age     : " << Male.age << " years old. \n";
  cout << "Persons Address : " << Male.address << "\n";
  return 0;
}

No comments:

Post a Comment