Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Last active August 29, 2015 14:18
Show Gist options
  • Save krysseltillada/26869895238ce40ec632 to your computer and use it in GitHub Desktop.
Save krysseltillada/26869895238ce40ec632 to your computer and use it in GitHub Desktop.
a simple c++ data structure class
///simple data structure program --> a simple exercise program from the book i've been study it might help to some people :D
//// for class Studentrecord --> methods
/// object.display(); - displays the values in the object :: expects no argument
/// object.setIdnum(int); - sets the id number :: expects a integer value argument
/// object.setCredits(double); - sets the credits value :: expects a double or integer value argument
/// object.setGradeave(double); - sets the average grade :: expects a double or interger value argument
//// for class Studentinfo --> methods
/// object.display(); - displays the values in the object :: expects no argument
/// object.setStudentname(string); - sets the name of the student :: expects a string argument
/// object.setDate(int, int, int); - sets a date :: expects a three integer argument
/// object.setCredits(double); - sets a credits value :: expects a double or integer argument
/// object.setGradeave(double); - sets the average grade :: expects a double or integer argument
//// for class Mail_list --> methods
/// object.display(); - displays the value in the object :: expects no argument;
/// object.setTitlefield(string); - sets the title of the mail :: expects a string argument
/// object.setLastname(string); - sets the last name :: expects a string argument
/// object.setFirstname(string); - sets the first name :: expects a string argument
/// object.setAddress1(string); - sets the first address :: expects a string argument
/// object.setAddress2(string); - sets the seconds address :: expects a string argument
/// object.setCityfield(string); - sets the name of the city :: expects a string argument
/// object.setStatefield(string); - sets the state :: expects a string argument
//// for class Stockinfo --> methods
/// object.display(); - displays the values in the object :: expects no argument
/// object.setStockname(string); - set the name of stock :: expects a string argument
/// object.setPrice(double); - sets a price :: expects a double or integer argument
/// object.setDate(int, int, int); - sets a date :: expects three integer argument
//// for class Inventory --> methods
/// object.display(); - displays the values in the object :: expects no argument
/// object.setPartnum(int); - set the part no. :: expects a integer argument
/// object.setPartdescrip(string); - sets the some description :: expects a string argument
/// object.setNumparts(int); - sets the number of parts :: expects a integer argument
/// object.setReordernum(int); - sets the reorder no. :: expects a integer argument
//// you can use this code freely :D
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Studentrecord
{
private:
int idnum;
double credits;
double gradeave;
public:
Studentrecord(int i = 0, double c = 0, double g = 0)
{idnum = i; credits = c; gradeave = g;}
void display();
void setIdnum(int);
void setCredits(double);
void setGradeave(double);
};
void Studentrecord::display()
{
cout << "\nid number: " << idnum
<< "\nnumber of credits completed: " << credits
<< "\ngrade point average: " << gradeave << endl;
return;
}
void Studentrecord::setIdnum(int i)
{
idnum = i;
return;
}
void Studentrecord::setCredits(double i)
{
credits = i;
return;
}
void Studentrecord::setGradeave(double i)
{
gradeave = i;
return;
}
class Studentinfo
{
private:
string studentname;
int month;
int day;
int year;
double credits;
double gradeave;
public:
Studentinfo(string a = "NONE", int m = 2, int d = 22, int y = 2012)
{studentname = a; month = m; day = d; year = y;}
void display();
void setStudentname(string);
void setDate(int, int, int);
void setCredits(double);
void setGradeave(double);
};
void Studentinfo::display()
{
cout << "\nstudent name: " << studentname
<< "\ndate of birth: " << setfill('0') << setw(2) << month << '/' << setw(2) << day << '/' << setw(2) << year
<< "\nnumber of credits completed: " << credits
<< "\ngrade point average: " << gradeave << endl;
return;
}
void Studentinfo::setStudentname(string nameinput)
{
studentname = nameinput;
return;
}
void Studentinfo::setDate(int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
return;
}
void Studentinfo::setCredits(double creditinput)
{
credits = creditinput;
return;
}
void Studentinfo::setGradeave(double gradeinput)
{
gradeave = gradeinput;
return;
}
class Mail_list
{
private:
string titlefield;
string lastname;
string firstname;
string address1;
string address2;
string cityfield;
string statefield;
int zipcode;
public:
Mail_list(string t = "NONE", string l = "NONE", string f = "NONE", string a1 = "NONE", string a2 = "NONE", string c = "NONE", string s = "NONE")
{titlefield = t; lastname = l; firstname = f; address1 = a1; address2 = a2; cityfield = c; statefield =s;}
void display();
void setTitlefield(string);
void setLastname(string);
void setFirstname(string);
void setAddress1(string);
void setAddress2(string);
void setCityfield(string);
void setStatefield(string);
};
void Mail_list::display()
{
cout << "\ntitle: " << titlefield
<< "\nLast name: " << lastname
<< "\nFirst name: " << firstname
<< "\nAddress 1: " << address1
<< "\nAddress 2: " << address2
<< "\nCity: " << cityfield
<< "\nState: " << statefield << endl;
return;
}
void Mail_list::setTitlefield(string title)
{
titlefield = title;
return;
}
void Mail_list::setLastname(string last)
{
lastname = last;
return;
}
void Mail_list::setFirstname(string first)
{
firstname = first;
return;
}
void Mail_list::setAddress1(string add1)
{
address1 = add1;
return;
}
void Mail_list::setAddress2(string add2)
{
address2 = add2;
return;
}
void Mail_list::setCityfield(string city)
{
cityfield = city;
return;
}
void Mail_list::setStatefield(string state)
{
statefield = state;
return;
}
class Stockinfo
{
private:
string stockname;
double price;
int month;
int day;
int year;
public:
Stockinfo(string s = "NONE", double p = 0, int mm = 2, int dd = 22, int yyyy = 2012)
{ stockname = s; price = p; month = mm; day = dd; year = yyyy;}
void display();
void setStockname(string);
void setPrice(double);
void setDate(int, int, int);
};
void Stockinfo::display()
{
cout << "\nstock name: " << stockname
<< "\npurchase price: " << price
<< "\ndate purchase: " << setfill('0') << setw(2) << month << '/' << setw(2) << day << '/' << setw(2) << year
<< endl;
return;
}
void Stockinfo::setStockname(string sname)
{
stockname = sname;
return;
}
void Stockinfo::setPrice(double assprice)
{
price = assprice;
return;
}
void Stockinfo::setDate(int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
return;
}
class Inventory
{
private:
int partnum;
string partdesprip;
int numparts;
int reordernum;
public:
Inventory(int p = 0, string pd = "NONE", int n = 0, int r = 0)
{partnum = p; partdesprip = pd; numparts = n; reordernum = r;}
void display();
void setPartnum(int);
void setPartdescrip(string);
void setNumparts(int);
void setReordernum(int);
};
void Inventory::setPartnum(int pn)
{
partnum = pn;
return;
}
void Inventory::setPartdescrip(string pd)
{
partdesprip = pd;
return;
}
void Inventory::setNumparts(int np)
{
numparts = np;
return;
}
void Inventory::setReordernum(int rn)
{
reordernum = rn;
return;
}
void Inventory::display()
{
cout << "\npart no: " << partnum
<< "\ndescription: " << partdesprip
<< "\nnumber in stock: " << numparts
<< "\nreorder number: " << reordernum << endl;
return;
}
int main()
{
Studentrecord student1;
student1.setIdnum(1999);
student1.setCredits(12.2);
student1.setGradeave(99.9);
student1.display();
Studentinfo student2;
student2.setStudentname("kryssel");
student2.setDate(12, 22, 2012);
student2.setCredits(22.2);
student2.setGradeave(99.0);
student2.display();
Mail_list mail1;
mail1.setTitlefield("hi");
mail1.setLastname("de leon");
mail1.setFirstname("kryssel");
mail1.setAddress1("rivera compund saint joseph subd");
mail1.setAddress2("i dont know what is my second address");
mail1.setCityfield("las pinas city");
mail1.setStatefield("city");
mail1.display();
Inventory inventory1;
inventory1.setPartnum(1002);
inventory1.setPartdescrip("what the fuck is this");
inventory1.setNumparts(2);
inventory1.setReordernum(4);
inventory1.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment