Proj1 : *** More hints *** - What you should be aiming for ...


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]

Posted by hussein on July 10, 1999 at 20:40:57:

since a lot of people are confused about what the program results should look like, heres what my solution generates ...
and, at the bottom you will find the actual main program body that generated the output - if you replace your main program with mine, you should get the same output i got ... and please use my code only for testing - use your own tests in your final version ...
---


Test 1 : 26 alternating enters/retrieves
Entering : a
Retrieving : a
Entering : b
Retrieving : b
Entering : c
Retrieving : c
Entering : d
Retrieving : d
Entering : e
Retrieving : e
Entering : f
Retrieving : f
Entering : g
Retrieving : g
Entering : h
Retrieving : h
Entering : i
Retrieving : i
Entering : j
Retrieving : j
Entering : k
Retrieving : k
Entering : l
Retrieving : l
Entering : m
Retrieving : m
Entering : n
Retrieving : n
Entering : o
Retrieving : o
Entering : p
Retrieving : p
Entering : q
Retrieving : q
Entering : r
Retrieving : r
Entering : s
Retrieving : s
Entering : t
Retrieving : t
Entering : u
Retrieving : u
Entering : v
Retrieving : v
Entering : w
Retrieving : w
Entering : x
Retrieving : x
Entering : y
Retrieving : y
Entering : z
Retrieving : z


Test 2 : 26 enters - overflow
Entering : a
Entering : b
Entering : c
Entering : d
Entering : e
Entering : f
Entering : g
Entering : h
Entering : i
Entering : j
Entering : k
Entering : l
Entering : m
Entering : n
Entering : o
Entering : p
Entering : q
Error : overflow
Entering : r
Error : overflow
Entering : s
Error : overflow
Entering : t
Error : overflow
Entering : u
Error : overflow
Entering : v
Error : overflow
Entering : w
Error : overflow
Entering : x
Error : overflow
Entering : y
Error : overflow
Entering : z
Error : overflow


Test 3 : 26 retrieves - underflow
Retrieving : a
Retrieving : b
Retrieving : c
Retrieving : d
Retrieving : e
Retrieving : f
Retrieving : g
Retrieving : h
Retrieving : i
Retrieving : j
Retrieving : k
Retrieving : l
Retrieving : m
Retrieving : n
Retrieving : o
Retrieving : p
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow
Retrieving : A
Error : underflow


---

char *ErrorMsg[] = {"", "Error : overflow\n", "Error : underflow\n"};

// main program body to test keyboard buffer

int main ()
{
KeyboardBuffer kb;
char i;

// check that enter and retrieve work
cout << "Test 1 : 26 alternating enters/retrieves\n";
for ( i='a'; i<='z'; i++ )
{
cout << "Entering : " << i << "\n";
kb.Enter (i);
cout << ErrorMsg[kb.Error ()];
cout << "Retrieving : " << kb.Retrieve () << "\n";
cout << ErrorMsg[kb.Error ()];
}
cout << "\n\n";

// check that overflow works
cout << "Test 2 : 26 enters - overflow\n";
for ( i='a'; i<='z'; i++ )
{
cout << "Entering : " << i << "\n";
kb.Enter (i);
cout << ErrorMsg[kb.Error ()];
}
cout << "\n\n";

// check that underflow works
cout << "Test 3 : 26 retrieves - underflow\n";
for ( i='a'; i<='z'; i++ )
{
cout << "Retrieving : " << kb.Retrieve () << "\n";
cout << ErrorMsg[kb.Error ()];
}
cout << "\n\n";
}


---


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2604 Discussion WWWBoard ] [ FAQ ]