Journals
Saturday,Jul 26 2003, 08:30:00 PMI took lots of pics these days. I juz...
I took lots of pics these days. I juz uploaded them to imagestation. So check out my life in UST by clicking the link below ~ ^^

Friday,Jul 25 2003, 04:04:00 AMI know it is extremely boring to see C++...
I know it is extremely boring to see C++ here all the time in my xanga... but I gonna put it here to keep record leh~
ANywayz, This had been a nice week again~ Besides the Typhoon which causes leakage through some holes at the corner of the air-conditioner and the postpone of Pop Song Singing contest, it's pretty nice here.
I had lots of fun here~ Many laugh_position and explosive_laughs ... too many that I can't quote all here lar~ My group of friends in UST including me, Freda, EEEEE-fun, Javy, JacTong, Salina, Bethany and WinnieC are all hyperactive!!! hehe~ I can't help laughing all the time..everyone du ~ Even BetBet started to lar!!!
*********************************
MONDAY
JacTong did a very stupid action -- "daan bb dai" ~ REVEnge started. Freda and I got Plan A, to get ray_diagram to look at the whole process, but didn't succeed. Fat Hung was so mo noi as I asked him to look at the whole process. JacTong is our common enemy (or revengeeee) that day~ hohohoohoho~ [I not gonna post the details here... ask me lar~ hahah]
TUESDAY
Know that Typhoon is coming.... Worried that it gonna ruin my WEdnesday and Thursday plan lar!!! So angry!
WEDNESDAY
Luckily the popsong singing contest was postponed, coz' it's in a very terrible condition in UST. When Typhoon signal #3 was hoisted, we felt like we were walking in Signal #10 already! Honestly, I was a bit afraid that we would be blown up to the sky... luckily we didn't. We linked our arms together to walk in the wind (cluster effect!!! haha) I was hoping that the contest gonna postpone so that I do not need to travel for such a long time PLUS in heavy RAIN!!! That afternoon, water started leaking into our room, as our room faces the sea... Rain knock heavily on the glass of our window.. Thanks to Javy's Design!! Good One ^^ Then I went to Common room to play with the other guys till four in the morning.... exhausted~
THURSDAY
Woke up at 11am , as there's no school in the morning. Queenie called to check if she gonna come in~ Negotiating for a long time, Queenie finally came at around 4pm~~ So happy ^^ Then two of us and Janis (^^ big mouth) went to eat afternoon Tea~ Then I went to COMP 102 Lab late, then DINNER ^^ lots of laughs!! We illustrated some JOKES throughout the week to Queenie... heheeh Laugh Die jor~ coz' it's reli TOOOOOO funny ~ WE had great time ~ QUeenie came to my room for a while, then she had to go back home lu ~ Heheh~ That night , we played till 2am ,then I had to wait for my hair to dry , so I stayed awake in the common room until 3am.. Chatted with people and had some laughs....
FRIDAY
Noth really special today, besides some good metaphor~~~{cin.get(??)} hahahhahahah!!!! EEEE-fun and JacTONg should understand what I mean~!!! heheh~ So funny~ Then went to Starbucks with JacTong (GBux?!?!?) ^^ two or three weeks hadn't been to StarBucks lar!!!
*******************************
Highlights :
1)Raymond, Ah Git ~~
2)"Globalization", "Dictionary"... very grose
3)Very "Salina"
4)Fat HUng : "They add chlorine to the water ga bor..."!!!!!!
Wednesday,Jul 23 2003, 12:31:00 PM#include
void main() {
//declart
#include <iostream.h>
void main() {
//declartion
int upper_bound;
int integer=3;
bool prime=true;
int n;
cout << "Please enter the upperbound" << endl;
cin >> upper_bound;
cout << "The prime numbers are:"<< endl;
do {
prime=true;
for (n=2; n<upper_bound; n++)
{
if(integer%n==0)
prime=false;
}
if (prime)
cout << integer << endl;
integer++;
}while (integer<=upper_bound);
}
Tuesday,Jul 22 2003, 03:59:00 AMDim-sum Bill Calculator (Use of if...
Dim-sum Bill Calculator
(Use of if statements, while / do-while loops and function)
You are hired by ABC Restaurant to write a program for computing customer bills. The restaurant provides four kinds of "dims" namely small dim, medium dim, large dim and special dim. Small dim costs $8; Medium dim costs $10; Large dim costs $12 and Special dim costs $15.
You should use a while loop to let the user input the dim that the customer orders. Say, 1 for a small dim, 2 for medium dim... and 0 for the end of input. After the end of input, it displays the bill containing the total number of 4 kinds of dims consumed and the total money to the screen.
Since the restaurant is now in promotion period, each small dim and medium dim reduces $1 and each large dim and special dim reduces $2 after the 5th dim OF THE SAME KIND. You should use a function with two parameters to compute the price of each dim. The first parameter is the type of dim (1,2,3,4) and the second one is the total number of calculated dims. If the total number of calculated dims is greater than 5, the price will reduce $1 or $2.
Separate the function to another cpp file named bill.cpp and put your main function in file main.cpp. Include also a header file bill.h which contains the prototype of the function(s) in bill.cpp. In this lab, you will practise how to include more than one file within a project.
Tuesday,Jul 22 2003, 12:51:00 AM/* COMP102 (CyberU) Summer 2003 Lab 4 */ #inc
/*
COMP102 (CyberU) Summer 2003
Lab 4
*/
#include <iostream.h>
#include <iomanip.h>
const int APPROX = 10;
void get_inputs(int &x);
double e_pow_x(int x, int n);
double factorial(int n);
double power(int x, int n);
void to_integer(int& ,bool&);
int main()
{
int x=0;
char again = 'Y'; // variable for asking for continue running
do {
int i;
int n=1;
get_inputs(x);
for (i=1;i<=APPROX; i++){
cout << "e^" << x << " = " << setiosflags(ios::fixed) << setprecision(7)
<< e_pow_x(x,i) << endl;
}
// Note: setiosflags(ios::fixed) and setprecision(7) are I/O manipulators
// used for manipulating output format of the decimal values.
// You will learn how to use these in the later topic about I/O Manipulators.
/* write code here to ask the user whether to continue the program or not */
cout << "Perform approximation again for another value of x ? (Yes: 'Y'; No: other keys):";
cin >> again;
} while (again=='Y'); // this loop is for re-running the program
return 0;
}
/* a function used for getting input(s) from user
you should check the validity of user input
by making similar use of the example code in the lab work
*/
void get_inputs(int &x) {
bool is_integer;
cout << "Calculating e^x" << endl;
/* use a loop to check for user input by
using the function to_integer().
Ask for user input again if it is invalid
*/
do{
cout << "Please enter an integer: ";
to_integer(x,is_integer);
}while (is_integer==false);
cout << x << endl;
}
/*
this function is used for calculating e^x using the formula (#)
for a particular value of n.
*/
double e_pow_x(int x, int n)
{
double expo_x = 1;
int i;
for (i=1; i<=n; i++){
expo_x = expo_x + (power(x,i)/ factorial(i));
}
return expo_x;
}
/* this factorial function calculates the factorial n!
where n is a non-negative integer.
n! = n*(n-1)*(n-2)*....*2*1
(e.g. 4! = 4*3*2*1 = 24)
the function returns the computed result in double typed to prevent from
integer overflow due to large value of n.
you may want to use a for loop or while loop to complete this function
*/
double factorial(int n)
{
double fact=1;
int i=1;
for (i=1; i<=n; i++){
fact*=i;
}
return fact;
}
/*
this function takes 2 parameters x and n
it calculates and returns x to the power of n
(e.g. power(3,4) returns 3*3*3*3 which is 81
You probably need to use a loop (for loop or while loop)
to implement this function
*/
double power(int x, int n)
{ int i; double powerr=1;
for (i=1; i <=n; i++){
powerr *=x;
}
return powerr;
}
/*
this function is for checking validity of user's integer input
this is the function we've gone through in the lab
you are strongly encouraged to understand the code first and write
it by your own again
*/
void to_integer(int& integer,bool& is_integer) {
int base=10;
char ch;
bool is_negative=false,first_digit=true;
/*initialization*/
integer=0;
is_integer=true;
while(true){
cin.get(ch);
if (ch=='\n' && first_digit==true)
/*handles the case: just press enter*/
{
is_integer=false;
return;
}else if (ch=='\n')
/*reads all the digits and break the loop*/
{
break;
}else if (ch=='-' && first_digit==true)
/*handles negative value and prevents the case: --3*/
{
is_negative=true;
first_digit=false;
}else if ((ch-'0')<0 || (ch-'0')>9)
/*handles non integer value*/
{
is_integer=false;
while(cin.get(ch) && ch!='\n');
return;
}else
/*handles the digit and converts it to integer value*/
{
integer=integer*base+(ch-'0');
first_digit=false;
}
}
if (is_negative)
integer*=-1;
}

