Saturday, January 31, 2009
Lab Exam
Visit this site - http://www.coders2020.com/what-is-infix-prefix-postfix-how-can-you-convert-from-one-representation-to-another-how-do-you-evaluate-these-expressions. This will serve as your guide for your upcoming midterm lab exam this monday.
Saturday, January 24, 2009
Stack and Queue
The codes for stack and queue are already available under Course Materials-> Handouts/ Learning Modules in elms.
Monday, January 12, 2009
Top Students for Prelim
1. EMAN, ROÑARD C. (BSIT2B) 96
2. PAASA, PATRICK ANGELO P. (BSIT2C) 93
3. LASAY, NORRIS LEMUEL C. (BSCS2) 90
4. ZABATE, MARVIN JOHN B. (BSCS2) 88
5. LUI, ADRIAN E.(BSCS2) 88
6. JAMIO, PAUL JOHN I. (BSIT2B) 88
7. MEDILLO, DARWIN I. (BSIT2A) 88
8. REANCHO, LIRALYN S.(BSIT2A) 88
9. AMARANTO, MAYLYN T. (BSIT2C) 88
10. BERNARDINO, JAMES CARL H. (BSIT2C) 88
11. CARILLO, RAFFY D. (BSCS2) 88
2. PAASA, PATRICK ANGELO P. (BSIT2C) 93
3. LASAY, NORRIS LEMUEL C. (BSCS2) 90
4. ZABATE, MARVIN JOHN B. (BSCS2) 88
5. LUI, ADRIAN E.(BSCS2) 88
6. JAMIO, PAUL JOHN I. (BSIT2B) 88
7. MEDILLO, DARWIN I. (BSIT2A) 88
8. REANCHO, LIRALYN S.(BSIT2A) 88
9. AMARANTO, MAYLYN T. (BSIT2C) 88
10. BERNARDINO, JAMES CARL H. (BSIT2C) 88
11. CARILLO, RAFFY D. (BSCS2) 88
Saturday, January 3, 2009
Templates
Function templates
Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type.
In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function. These function templates can use these parameters as if they were any other regular type.
The format for declaring function templates with type parameters is:
template function_declaration;
template function_declaration;
The only difference between both prototypes is the use of either the keyword class or the keyword typename. Its use is indistinct, since both expressions have exactly the same meaning and behave exactly the same way.
For example, to create a template function that returns the greater one of two objects we could use:
Example
Class templates
We also have the possibility to write class templates, so that a class can have members that use template parameters as types. For example:
Example:
Template Specialization
Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type.
In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function. These function templates can use these parameters as if they were any other regular type.
The format for declaring function templates with type parameters is:
template
template
The only difference between both prototypes is the use of either the keyword class or the keyword typename. Its use is indistinct, since both expressions have exactly the same meaning and behave exactly the same way.
For example, to create a template function that returns the greater one of two objects we could use:
template <class myType>
myType GetMax (myType a, myType b) {
return (a>b?a:b);
}
Example
// function template
#include
using namespace std;
template <class T>
T GetMax (T a, T b) {
T result;
result = (a>b)? a : b;
return (result);
}
int main () {
int i=5, j=6, k;
long l=10, m=5, n;
k=GetMax<int>(i,j);
n=GetMax<long>(l,m);
cout <<>return 0;
}
Class templates
We also have the possibility to write class templates, so that a class can have members that use template parameters as types. For example:
template <class T>
class mypair {
T values [2];
public:
mypair (T first, T second)
{
values[0]=first; values[1]=second;
}
};
Example:
// class templates
#include
using namespace std;
template <class T>
class mypair {
T a, b;
public:
mypair (T first, T second)
{a=first; b=second;}
T getmax ();
};
template <class T>
T mypair::getmax ()
{
T retval;
retval = a>b? a : b;
return retval;
}
int main () {
mypair <int> myobject (100, 75);
cout <<>return 0;
}
Template Specialization
// template specializationObserve the results of the codes above. A short quiz will be given about this during lecture.
#include
using namespace std;
// class template:
template <class T>
class mycontainer {
T element;
public:
mycontainer (T arg) {element=arg;}
T increase () {return ++element;}
};
// class template specialization:
template <>
class mycontainer <char> {
char element;
public:
mycontainer (char arg) {element=arg;}
char uppercase ()
{
if ((element>='a')&&(element<='z'))
element+='A'-'a';
return element;
}
};
int main () {
mycontainer<int> myint (7);
mycontainer<char> mychar ('j');
cout <<>return 0;
}
Subscribe to:
Posts (Atom)