Sign in or Sign up

C++ Class Example <3
Started by Zens


Rate this topic
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


2 posts in this topic
Zens Offline
Junior Member
**


Registered
Posts: 23
Threads: 3
Joined: Sat Sep 2017
Reputation: 0

CZPoints: 3 CZP
10-06-2017, 09:20 PM -
#1
Code:
#include <iostream>
#include <string>
#include <windows.h>

using std::cin;
using std::cout;
using std::endl;
using std::string;

class Account {
   char FirstName[8];
   char LastName[8];
   string FullName;
   int AccountNumber;
   int Ammount;
   
   public:
       void InputData() {
           cout << "First Name     : "; cin >> FirstName;
           cout << "Last Name      : "; cin >> LastName;
           cout << "Account Number : "; cin >> AccountNumber;
           cout << "Ammount        : "; cin >> Ammount;
       }
       void ShowAccountNumber() {
           cout << "Account Number : " << AccountNumber << endl;
       }
       void ShowAccountName() {
           cout << "First Name     : " << FirstName << endl;
           cout << "Last Name      : " << LastName << endl;
           cout << "Full Name      : " << FirstName << " " << LastName << endl;
       }
       void ShowAccountAmmount() {
           cout << "Ammount        : " << Ammount << endl;
       }
};

int main() {
   Account A;
   A.InputData();
   system("cls");
   A.ShowAccountNumber();
   A.ShowAccountName();
   A.ShowAccountAmmount();
}

This is a simple C++ class
Goodluck
This post was last modified: 10-06-2017, 11:25 PM by Zens. Edit Reason: i put useless header file
[Image: WAhuMDL.png]
deadeye Offline
Programmer
***


Registered
Posts: 246
Threads: 19
Joined: Sat Apr 2017
Reputation: 2

CZPoints: 27 CZP
HQMember
10-06-2017, 11:00 PM -
#2
It's nice to see that you want to teach us! :)
But maybe you could explain for coder newbies, what this code is in detail, what it does and how it works?
[Image: cw2gsbi.png]

Discord: deadeye#7164

Disclaimer: I have no idea what I'm talking about.
Zens Offline
Junior Member
**


Registered
Posts: 23
Threads: 3
Joined: Sat Sep 2017
Reputation: 0

CZPoints: 3 CZP
10-06-2017, 11:30 PM -
#3
#include <iostream> is used to declare std::cin and std::cout

#include <string> for std::string

#include <windows.h> for the "system("cls");

I highly not suggest to use "using namespace std" because of this
https://stackoverflow.com/questions/1452...d-practice

And i use Variable.Function(); to call the function that i declared inside of class ;)
[Image: WAhuMDL.png]




Users browsing this thread: 1 Guest(s)