not exactly correct, just give the idea
#include "tqueue.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
Tqueue<int> Q;
if(argv[1][0]== '-' && argv[1][1] == 'a'){
int i;
for(i=0;i<argc-2;i++){
if(sscanf(argv[i],"%d")
Q.append(argv[i]);
else{
count<<"Incorrect call use as follows:"<<endl;
count<<"tq -[a][d] 99 [99 99 ...]"<<endl;
break;
}
Q.sort(true);
do{
cout<<Q.visit()<<" ";
}while(Q.goNext());
}
else if(argv[1][0]== '-' && argv[1][1] == 'd'){
int i;
for(i=0;i<argc-2;i++){
if(sscanf(argv[i],"%d")
Q.append(argv[i]);
else{
count<<"Incorrect call use as follows:"<<endl;
count<<"tq -[a][d] 99 [99 99 ...]"<<endl;
break;
}
Q.sort(true);
do{
cout<<Q.visit()<<" ";
}while(Q.goPrev());
}
return 0;
}
Tuesday, April 17, 2012
Wednesday, March 14, 2012
Using cout to print binary
#include <cstdio>
#include<iostream>
using namespace std;
char* bits(int val){
const int m = sizeof(int)*8;
static char str[m];
int i;
int j;
for(i = m-1, j = 0; i>=0;i--,j++){
if(val & (1<<i))
str[j] = '1';
else
str[j] = '0';
}
return str;
}
int main () {
int i = 2345;
cout << " i: " << bits(i) << endl;
return 0;
}
#include<iostream>
using namespace std;
char* bits(int val){
const int m = sizeof(int)*8;
static char str[m];
int i;
int j;
for(i = m-1, j = 0; i>=0;i--,j++){
if(val & (1<<i))
str[j] = '1';
else
str[j] = '0';
}
return str;
}
int main () {
int i = 2345;
cout << " i: " << bits(i) << endl;
return 0;
}
Monday, March 12, 2012
my setOn and setOff
void setOn(unsigned int& val, int bitNo){
retuen val = val | (1 << bitNo);
}
void setOff(unsigned int& val, int bitNo){
retuen val = val & ~(1 << bitNo);
}
retuen val = val | (1 << bitNo);
}
void setOff(unsigned int& val, int bitNo){
retuen val = val & ~(1 << bitNo);
}
Sunday, February 12, 2012
week 5 wiki answer
int validMonth(int mon, char* errmes){ int res = 0; if(mon > 0 && mon <=12){ res = 1; } else{ strcpy(errmes, "Invalid month (1<=month<=12)"); } return res; }write the above function in one line:
int validMonth(int mon, char* errmes){ return yada yada; }
answer:
return((mon>0 && mon <=12) || !strcpy(errmes, "Invalid month!"));
Tuesday, January 31, 2012
problem with test 4.17
Can anyone help me to get through test 4.17?
- console.edit() was supposed to return Unknown Keycode, Dec: 0 Hex: 0
but instead it returned: ENTER, Dec: 10 Hex: A
What does it mean? Anyone had a some problem and fixed it already?
- console.edit() was supposed to return Unknown Keycode, Dec: 0 Hex: 0
but instead it returned: ENTER, Dec: 10 Hex: A
What does it mean? Anyone had a some problem and fixed it already?
Subscribe to:
Posts (Atom)