date類
#ifndef date_hpp
#define date_hpp
#include
class
date
;#endif /* date_hpp */
#include "date.hpp"
#includeusing namespace std;
date::date(){}
date::date( int
day, int
month, int
year )
void date::print() const
;#endif /* person_hpp */
#include "person.hpp"
#include
#include
using
namespace
std;
person::person(void){}
person::person(char * their_name, char * email, int day, int month, int year):date(day,month,year)
char * person::getname() const
char * person::getemailaddress() const
date person::getbirthdate() const
void person::print() const
if( email_address != null)
cout
<<"person析構函式!"
#ifndef personset_hpp
#define personset_hpp
#include"date.hpp"
#include"person.hpp"
#include
class
personset
;#endif /* personset_hpp */
#include "personset.hpp"
#include
using
namespace
std;
personset::personset (int initial_size)
personset::~ personset (void)
cout
<<"personset析構函式!"
_capacity *= 2;
delete temp;
}_elements[_size] = element;
_size++;
}person& personset::nextelement() //呼叫時先判斷_index的值是否大於_size;
return *_elements[_index++];
}// 從set中移除最後乙個成員,如果set空的資料超過一半,釋放一些記憶體
person& personset::removeelement()
_capacity /= 2;
delete temp;
}return *p;
}//從set中的index索引處移除成員。如果set空的資料超過一半, 釋放一些記憶體
person& personset:: removeelement( int index )
_size--;
if(_size < _capacity / 2)
_capacity /= 2;
delete temp;
}return *p;
}int personset::size() const
//answer the number of elements in the set.
void personset::print() const
//print the elements of the set
}
main.cpp
#include"date.hpp"
#include"person.hpp"
#include"personset.hpp"
#include
using
namespace
std;
int main(int argc, const
char * argv)
personset boys, girls;
boys.add( p1);
if (p1 != &boys.removeelement() )
else
boys.add( p1);
boys.add( p2);
girls.add( p3);
boys.add((new person((char*)"john",(char*) "[email protected]", 20, 3, 1967)));
girls.add((new person((char*)"sue",(char*) "[email protected]", 20, 3, 1967)));
boys.add((new person((char*)"frank",(char*)"[email protected]", 25, 4, 1958)));
girls.add((new person((char*)"mary",(char*) "[email protected]", 25, 4, 1955)));
boys.add((new person((char*)"john", (char*)"johnchat.ca", 12, 12, 1970)));
boys.add((new person((char*)"john",(char*) "[email protected]", 20, 3, 1967)));
girls.add((new person((char*)"sue",(char*) "[email protected]", 20, 3, 1967)));
boys.add((new person((char*)"frank",(char*)"[email protected]", 25, 4, 1958)));
girls.add((new person((char*)"mary",(char*) "[email protected]", 25, 4, 1955)));
boys.add((new person((char*)"john", (char*)"johnchat.ca", 12, 12, 1970)));
int numberofboys = boys.size();
cout
<< "number of boys = "
<< numberofboys << endl;
for(int i = 0; i<7; i++)
cout
<< "number of boys = "
<< boys.size() << endl;
boys.print();
// person & boy = boys.removeelement();
// boy.print();
// delete &boy;
// for(int i = 0; i//
cout
<< "number of girls = "
<< girls.size() << "\n";
int numberofgirls = girls.size();
for(int i = 0; ifor(int i = 0; i//delete all the girls from the heap
return
0;}
基礎練習 組合數
題目來自 codevs 1631 洛谷 1173 很簡單的遞推題目 由劉汝佳紫皮 今後簡稱 ruka 衍伸想要做的這道題目 稍後我將ruka版 發上來 本題 如下 include include define num 100003 using namespace std long long a 10...
演算法練習 排列組合之組合和
給出一組不同的正整數序列和乙個目標值,求出全部可能的組合,使得組合裡全部元素和為目標值。要求 1 每乙個組合裡的元素依照公升序排列。2 輸出組合裡不含有反覆的組合。3 輸入序列中的整數能夠多次使用。舉例 輸入 目標值為7 輸出。為了讓輸出元素按公升序排列,可對輸入序列進行排序。同這裡我們使用遞迴的方...
練習,求組合公式值
求組合數公式為 編一程式,輸入m和n 的值,求組合數。要求分別定義求階乘和求組合的函式,求組合數的函式呼叫求階乘的函式來實現求解,在 main 函式中,負責輸入輸出及呼叫求組合數的函式。include using namespace std int fac int int main int m,n ...