2012-03-21 01:30:59 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* C++ Test Program
|
|
|
|
*/
|
2012-01-19 06:12:04 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <queue>
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* A class */
|
2012-01-19 06:12:04 +04:00
|
|
|
class test {
|
|
|
|
private:
|
2012-03-21 01:30:59 +04:00
|
|
|
/* With a little private integer */
|
2012-01-19 06:12:04 +04:00
|
|
|
int i;
|
|
|
|
public:
|
|
|
|
test() {
|
2012-03-21 01:30:59 +04:00
|
|
|
/* That starts at zero */
|
2012-01-19 06:12:04 +04:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
void inc() {
|
2012-03-21 01:30:59 +04:00
|
|
|
/* And can be incremented */
|
2012-01-19 06:12:04 +04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
int value() {
|
2012-03-21 01:37:49 +04:00
|
|
|
/* And can have its value retrieved */
|
2012-01-19 06:12:04 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
2012-03-21 01:30:59 +04:00
|
|
|
/*
|
|
|
|
* HACK: We need to execute ios_base::Init() to ensure the base
|
|
|
|
* IO objects are accessible (this would normally be called by
|
|
|
|
* the static constructor for std::__ioinit, but we don't currently
|
2012-03-21 01:37:49 +04:00
|
|
|
* execute static constructors as we never execute the .init section)
|
2012-03-21 01:30:59 +04:00
|
|
|
*/
|
2012-03-21 01:22:50 +04:00
|
|
|
std::ios_base::Init();
|
2012-03-21 01:30:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First test: Print "Hello world" and a new line.
|
|
|
|
*/
|
2012-01-19 06:12:04 +04:00
|
|
|
std::cout << "Hello world\n";
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Create a test object */
|
2012-01-19 06:12:04 +04:00
|
|
|
test * t = new test();
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Print its value = 0 */
|
2012-01-19 06:12:04 +04:00
|
|
|
printf("%d\n", t->value());
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Increment it */
|
2012-01-19 06:12:04 +04:00
|
|
|
t->inc();
|
2012-03-21 01:30:59 +04:00
|
|
|
/* And print again = 1 */
|
2012-01-19 06:12:04 +04:00
|
|
|
printf("%d\n", t->value());
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Create a queue */
|
2012-01-19 06:12:04 +04:00
|
|
|
std::queue<int> q;
|
|
|
|
q.push(4);
|
|
|
|
q.push(20);
|
|
|
|
q.push(5);
|
|
|
|
q.push(19);
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Print out the values in order */
|
2012-01-19 06:12:04 +04:00
|
|
|
while (!q.empty()) {
|
|
|
|
printf("%d\n", q.front());
|
|
|
|
q.pop();
|
|
|
|
}
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Read in a string */
|
2012-01-19 06:12:04 +04:00
|
|
|
std::string s;
|
|
|
|
std::cin >> s;
|
|
|
|
|
2012-03-21 01:30:59 +04:00
|
|
|
/* Print it and its length */
|
2012-01-19 06:12:04 +04:00
|
|
|
printf("%d: %s\n", s.length(), s.c_str());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|