Upload the test files for the examples folder.
This commit is contained in:
parent
c5d797cfbb
commit
eb191a70b4
3 changed files with 96 additions and 0 deletions
71
examples/constructors.cpp
Normal file
71
examples/constructors.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
||||
class DayOfYear
|
||||
{
|
||||
private:
|
||||
int month;
|
||||
int day;
|
||||
void testDate();
|
||||
public:
|
||||
DayOfYear(int monthValue, int dayValue);
|
||||
DayOfYear(int monthValue);
|
||||
DayOfYear();
|
||||
|
||||
void input();
|
||||
void output();
|
||||
int getMonthNumber();
|
||||
int getDay();
|
||||
};
|
||||
|
||||
DayOfYear::DayOfYear(int monthValue, int dayValue)
|
||||
: month(monthValue), day(dayValue)
|
||||
{
|
||||
testDate();
|
||||
}
|
||||
|
||||
DayOfYear::DayOfYear(int monthValue)
|
||||
: month(monthValue), day(1)
|
||||
{
|
||||
testDate();
|
||||
}
|
||||
|
||||
DayOfYear::DayOfYear()
|
||||
: month(1), day(1)
|
||||
{}
|
||||
|
||||
void DayOfYear::testDate()
|
||||
{
|
||||
//
|
||||
if((month < 1) || (month > 12))
|
||||
{
|
||||
//
|
||||
cout << "Invalid month.\n";
|
||||
}
|
||||
if((day < 1) || (day > 31))
|
||||
{
|
||||
//
|
||||
cout << "Invalid day.\n";
|
||||
}
|
||||
}
|
||||
|
||||
void DayOfYear::output()
|
||||
{
|
||||
string Months [] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
cout << "The month is " << Months[month-1] << " and the day is " << day;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
DayOfYear date1(2, 21), date2(5), date3;
|
||||
cout << "Initialized dates:" << endl;
|
||||
date1.output(); cout << endl;
|
||||
date2.output(); cout << endl;
|
||||
date3.output(); cout << endl;
|
||||
|
||||
date1 = DayOfYear(10, 31);
|
||||
cout << "Date 1 reset to the following: " << endl;
|
||||
date1.output(); cout << endl;
|
||||
return 0;
|
||||
}
|
||||
BIN
examples/test
Executable file
BIN
examples/test
Executable file
Binary file not shown.
25
examples/test.cpp
Normal file
25
examples/test.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void printSize(int array[])
|
||||
{
|
||||
//
|
||||
cout << sizeof(*array) << "\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//
|
||||
int array[] = {1, 2, 3, 4, 5, 6};
|
||||
cout << sizeof(array) << "\n";
|
||||
printSize(array);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue