Wednesday, March 13, 2013
DLL - Append
void DLL::append(int data){
if(_tail != NULL){
_tail->_next = new Node(data, _tail->_prev, _tail);
}
}
Tuesday, February 19, 2013
Oopers Group 8 - Wiki Team Page
Go Team 8 of OOP344 Winter 2013 Semester. First time doing a wiki page, and it looks pretty decent job if I don't say so myself : http://zenit.senecac.on.ca/wiki/index.php/OOP344_20131_Oopers
Sunday, January 20, 2013
OOP344 Week2 Environmental Variable Search and Display
// OOP344 Week2 Environmental Variable Search and Display -- Peter Huang
// Program finds a user entered environmental variable (case insensitive). It displays
// the variable and the value/path of the data.
#include <iostream>
#include <cstring>
using namespace std;
// #define DEBUG
#define usrMAX strlen(argv[1])
#define arrMAX strlen(env[arr])
int main(int argc, char* argv[], char* env[])
{
int i;
int j;
int arr;
int pos;
int flag = 0;
char usrSearch[usrMAX+1];
strcpy(usrSearch,argv[1]); // copy search string to user search array
char searchEnv[usrMAX+1];
for(i = 0; env[i] && flag == 0; i++)
{
if(flag == 0) // loops and passes environmental variable string element, only to the length of user search array
{
for(j = 0; j < usrMAX; j++)
searchEnv[j] = env[i][j];
searchEnv[j] = '\0';
if(stricmp(usrSearch,searchEnv) == 0) // index the env array and pos when user search and environmental name match (case insensitive)
{
pos = j;
arr = i;
flag = 1;
}
}
}
if(flag == 1) // when match, finds which environmental index and the last pos (the actual data/path) and passes into a value array to output.
{
char searchVal[arrMAX];
for(i = 0; i < arrMAX; i++)
{
if(env[arr][pos+i] != '\0')
searchVal[i] = env[arr][pos+i];
}
searchVal[i] = '\0';
cout << searchEnv << searchVal << endl;
}
else
cout << "Not found" << endl;
#ifdef DEBUG // fardad's code for listing environmental variables
for(i=0;env[i] != 0;i++){
cout<<i<<": "<<env[i]<<endl;
}
#endif
return 0;
}
// Program finds a user entered environmental variable (case insensitive). It displays
// the variable and the value/path of the data.
#include <iostream>
#include <cstring>
using namespace std;
// #define DEBUG
#define usrMAX strlen(argv[1])
#define arrMAX strlen(env[arr])
int main(int argc, char* argv[], char* env[])
{
int i;
int j;
int arr;
int pos;
int flag = 0;
char usrSearch[usrMAX+1];
strcpy(usrSearch,argv[1]); // copy search string to user search array
char searchEnv[usrMAX+1];
for(i = 0; env[i] && flag == 0; i++)
{
if(flag == 0) // loops and passes environmental variable string element, only to the length of user search array
{
for(j = 0; j < usrMAX; j++)
searchEnv[j] = env[i][j];
searchEnv[j] = '\0';
if(stricmp(usrSearch,searchEnv) == 0) // index the env array and pos when user search and environmental name match (case insensitive)
{
pos = j;
arr = i;
flag = 1;
}
}
}
if(flag == 1) // when match, finds which environmental index and the last pos (the actual data/path) and passes into a value array to output.
{
char searchVal[arrMAX];
for(i = 0; i < arrMAX; i++)
{
if(env[arr][pos+i] != '\0')
searchVal[i] = env[arr][pos+i];
}
searchVal[i] = '\0';
cout << searchEnv << searchVal << endl;
}
else
cout << "Not found" << endl;
#ifdef DEBUG // fardad's code for listing environmental variables
for(i=0;env[i] != 0;i++){
cout<<i<<": "<<env[i]<<endl;
}
#endif
return 0;
}
Tuesday, January 15, 2013
OOP344 Week2 Command Line Exercises
An exercise on week2 of Oop344 of all operations using commandline.
Add Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Add
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int sum = 0;
if(argc != 3)
cout << "Not valid add command. Command format is : add num1 num2" <<endl;
else{
for(int i = 1; i < argc; i++)
sum = sum + atoi(argv[i]);
cout << "Sum : " << sum <<endl;
}
return 0;
}
Subtract Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Subtract
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int dif = 0;
if(argc != 3)
cout << "Not valid subtract command. Command format is : sub num1(to) num2(from)" <<endl;
else {
dif = atoi(argv[1]) - atoi(argv[2]);
cout << "Difference : " << dif <<endl;
}
return 0;
}
Multiplication Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Multiply
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int ans;
if(argc != 3)
cout << "Not valid multiplication command. Command format is : mul num1 num2" <<endl;
else {
ans = atoi(argv[1]) * atoi(argv[2]);
cout << "Answer(Multiplication) : " << ans <<endl;
}
return 0;
}
Division Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Divide
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
double ans;
if(argc != 3)
cout << "Not valid division command. Command format is : div num1(numerator) num2(denominator)" <<endl;
else {
ans = double(atoi(argv[1])) / atoi(argv[2]);
cout.precision(2);
cout << "Answer(Division) : " << ans <<endl;
}
return 0;
}
Add Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Add
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int sum = 0;
if(argc != 3)
cout << "Not valid add command. Command format is : add num1 num2" <<endl;
else{
for(int i = 1; i < argc; i++)
sum = sum + atoi(argv[i]);
cout << "Sum : " << sum <<endl;
}
return 0;
}
Subtract Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Subtract
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int dif = 0;
if(argc != 3)
cout << "Not valid subtract command. Command format is : sub num1(to) num2(from)" <<endl;
else {
dif = atoi(argv[1]) - atoi(argv[2]);
cout << "Difference : " << dif <<endl;
}
return 0;
}
Multiplication Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Multiply
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
int ans;
if(argc != 3)
cout << "Not valid multiplication command. Command format is : mul num1 num2" <<endl;
else {
ans = atoi(argv[1]) * atoi(argv[2]);
cout << "Answer(Multiplication) : " << ans <<endl;
}
return 0;
}
Division Command Line
// OOP344 Week2 Exercise Peter Huang CMDL Divide
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[], char* env[]) {
double ans;
if(argc != 3)
cout << "Not valid division command. Command format is : div num1(numerator) num2(denominator)" <<endl;
else {
ans = double(atoi(argv[1])) / atoi(argv[2]);
cout.precision(2);
cout << "Answer(Division) : " << ans <<endl;
}
return 0;
}
Subscribe to:
Posts (Atom)