Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
krysseltillada / io.cpp
Created July 17, 2015 09:26
i/o condition states ( ios::badbit, goodbit, eofbit, failbit && std::cin.bad(), good(), eof(), fail() )
#include <iostream> /// std::cout; std::endl;
int main ()
{
int i = 0;
std::cin >> i; /// inserting some data into the stream and returns a state return by input operator(insertion operetor)
if (std::cin.rdstate() == std::cin.badbit) /// checks the following conditions
@krysseltillada
krysseltillada / sm.cpp
Last active August 29, 2015 14:24
static member
#include <iostream>
class Account
{
public:
Account () = default;
Account (std::string n, int id, double m) :
name (n) , id_no (id), money (m) { }
void modify_prime (double);
@krysseltillada
krysseltillada / cc.cpp
Created July 13, 2015 12:50
constexpr constructors
#include <iostream>
class Debug {
public:
constexpr Debug (bool a, bool b, bool c):
hw (a), io (b), other (c) { }
constexpr Debug() : Debug(false, false, false) { }
constexpr Debug (bool aa) : Debug (false , false ,false) { }
constexpr Debug (bool aaa, bool bb) : Debug (false, false, false) { }
@krysseltillada
krysseltillada / e.cpp
Created July 12, 2015 13:37
class exercise
#include <iostream>
#include "exercise.h"
int main()
{
Book b1("lippman", "c++primer", "blahblah", "2211");
display(b1);
b1.modify_author("kryssel").modify_title("blah blah").modify_date("nov 28 1998").modify_isbn("2220-222");
@krysseltillada
krysseltillada / fmf.cpp
Created July 11, 2015 06:34
function member as friend
#include <iostream>
class Person;
class option
{
public:
typedef int number;
@krysseltillada
krysseltillada / dfmf.cpp
Created July 10, 2015 16:59
declaring function member as friend
#include <iostream>
class B; /// forward declaration to know the types in function members in Class A
class A
{
public:
void modify (B &,const int &);
int &display (B &);
@krysseltillada
krysseltillada / Sample_c.cpp
Created July 10, 2015 02:55
function methods in series of calls
#include <iostream>
#include <string>
#include "Sample_c.h"
Sample_c::Sample_c (std::string dat) :
data_member1 (dat) { }
Sample_c &Sample_c::f1 (char c1)
{
this->data_member1 = c1;
@krysseltillada
krysseltillada / Person.cpp
Created July 9, 2015 16:00
relationship between *this and function members
#include "Person.h"
#include <iostream>
#include <string>
/// implementation section
Person::Person (std::string n, std::string a) :
name (n), address (a) {}
const Person &Person::display () const
@krysseltillada
krysseltillada / Person.cpp
Created July 9, 2015 02:47
working with vectors and class
#include <iostream>
#include <string>
#include "Person.h"
Person::Person (std::string n, std::string a, int ag, int cn)
{
std::cout << "the object is created " << std::endl;
name = n;
address = a;
@krysseltillada
krysseltillada / Person.h
Created July 8, 2015 05:46
class person (with encapsulation)
#define PERSON_H
#ifdef PERSON_H
#include <iostream>
#include <string>
class Person
{
public: /// public specifier only accessible through all program