So, i just got the Sony Ereader PRS-T1 and my computer just doesn't seem to want to recognized it. I took a few hours of browsing the web for forums looking for solution, at the end i found nothing. AFTER i few moment later i finally found the solution with help.
1. Connect the device to your computer using the USB charger they supply
2. Check the top left of your device and see if there is the USB symbol (looks like a pitchfork)
3. If its there TOUCH IT!
4. your screen should change to something along the line data transfer
5. click on the only button on the screen and done! you computer should detect the device and ask you how you would like to open the device
Nothing but personal opinion of whats going on with my life and some codings :D
Wednesday, June 13, 2012
Sunday, April 15, 2012
Test 2 Q4 walkthrough with comments!
Q4:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct PhRec{
char name[60];
int PhoneNumber;
};
bool operator<(PhRec& left,
PhRec& right){
return strcmp(left.name, right.name) < 0;
}
#include "tqueue.h"
int main(){
fstream f("phones.bin", ios::in|ios::binary);//just reads the
file
PhRec pr;
Tqueue<PhRec> Q;//change all Tqueue type into PhRec type
while(f.good()){//continue in this loop if f.good() is true
f.read((char*)&pr, sizeof(pr));//reads the sizeof(pr) and store it
in &pr as a char*
if(f.good()){//if the previous read function worked go in here
Q.append(pr);//append pr (in this case is
a character string) to the queue list
}
}
f.close();
f.open("phones.bin", ios::out|ios::binary);//rewriting the
file
Q.sort(true);//sort the Queue list
while(!Q.isEmpty()){//continue this loop until the Queue list is empty
pr = Q.remove();//assign pr with the value of Q.remove();
f.write((const char*)&pr, sizeof(pr));//write sizeof(pr) bytes from
&pr as a char*
}
return 0;
}
Test 2 Q3 walkthrough with comments!:
//Q3
#include <iostream>
#include "tqueue.h"
using namespace std;
int main(int argc, char* argv[]){
bool badArgs = false;
bool Asc = false;
Tqueue<int> Q;//changing all "type" in tqueue class as int
if(argc < 3){//if there are less than 3 argument in argc
badArgs = true;
}
else{
if(argv[1][0] != '-'){//checks the first character
badArgs = true;
}
else{
if(argv[1][1] == 'a'){//checks the second character
Asc = true;
}
else if(argv[1][1] != 'd'){
badArgs = true;
}
int arg;
for(int i =2; !badArgs && i<argc;i++){//i=2; if !badArg is false and i < argc; i++
if(sscanf(argv[i],"%d", &arg) == 1){//look at argv[i], read it as an integer, store it into &arg, sscanf return
//sscanf returns the number of variable filled (in this case 1)
Q.append(arg);//append the value of arg at the end of the Qlist
}
else{
badArgs = true;
}
}
}
}
if(badArgs){
cout<<"Incorrect class use as follows:"<<endl<<"tq -[a|d] 99 [99 99 ...]"<<endl;
}
else{
Q.sort(Asc);//see if the bool(Ascending) is true or not in the function sort (bool sort(bool Ascending = true);)
//if true will sort the Qlist by ascending order or if false will go descending
while(!Q.isEmpty()){
cout<<Q.remove()<<" ";
}
cout<<endl;
}
return 0;
}
//Q3
#include <iostream>
#include "tqueue.h"
using namespace std;
int main(int argc, char* argv[]){
bool badArgs = false;
bool Asc = false;
Tqueue<int> Q;//changing all "type" in tqueue class as int
if(argc < 3){//if there are less than 3 argument in argc
badArgs = true;
}
else{
if(argv[1][0] != '-'){//checks the first character
badArgs = true;
}
else{
if(argv[1][1] == 'a'){//checks the second character
Asc = true;
}
else if(argv[1][1] != 'd'){
badArgs = true;
}
int arg;
for(int i =2; !badArgs && i<argc;i++){//i=2; if !badArg is false and i < argc; i++
if(sscanf(argv[i],"%d", &arg) == 1){//look at argv[i], read it as an integer, store it into &arg, sscanf return
//sscanf returns the number of variable filled (in this case 1)
Q.append(arg);//append the value of arg at the end of the Qlist
}
else{
badArgs = true;
}
}
}
}
if(badArgs){
cout<<"Incorrect class use as follows:"<<endl<<"tq -[a|d] 99 [99 99 ...]"<<endl;
}
else{
Q.sort(Asc);//see if the bool(Ascending) is true or not in the function sort (bool sort(bool Ascending = true);)
//if true will sort the Qlist by ascending order or if false will go descending
while(!Q.isEmpty()){
cout<<Q.remove()<<" ";
}
cout<<endl;
}
return 0;
}
Quick look at command line: int main(int argc, char* argv[])
#include <iostream>
using namespace std;
int main(int argc,char* argv[]){//argc holds the number of parameter +1 (-d del name = 4 arguments), argv[] holds each character in the array
int i;
if (argv[1][0] != '-'){
cout << "idk what: " << argv[1][0] << " is..."<< endl;
return -1;
}
else{
cout << argc << endl;
cout << "i know what that is" <<endl;
cout <<"Command executed: " <<endl;
cout << "-------------------------" <<endl;
cout << " argv[1][0]:" <<endl;
cout << argv[1][0] << endl;//must use argv[1][x] because argv[0][0] holds the file path name, command prompt accepts a string in the second row([1][x])
cout << " argv[1][1]:" <<endl;
cout << argv[1][1] << endl;//gets the second character of the command line
cout << " argv[1][2]:" <<endl;
cout << argv[1][2] << endl;//gets the third character of the command line
cout << " argv[1][3]:" <<endl;
cout << argv[1][3] << endl;
cout << " argv[1][4]:" <<endl;
cout << argv[1][4] << endl;
cout << " argv[2]:" <<endl;
cout << argv[2] << endl;//checks 2nd argument
cout << " argv[3]:" <<endl;
cout << argv[3] << endl;//checks 3rd argument
cout << " argv[4]:" <<endl;
cout << argv[4] << endl;//checks 4th argument
}
return 0;
}
#include <iostream>
using namespace std;
int main(int argc,char* argv[]){//argc holds the number of parameter +1 (-d del name = 4 arguments), argv[] holds each character in the array
int i;
if (argv[1][0] != '-'){
cout << "idk what: " << argv[1][0] << " is..."<< endl;
return -1;
}
else{
cout << argc << endl;
cout << "i know what that is" <<endl;
cout <<"Command executed: " <<endl;
cout << "-------------------------" <<endl;
cout << " argv[1][0]:" <<endl;
cout << argv[1][0] << endl;//must use argv[1][x] because argv[0][0] holds the file path name, command prompt accepts a string in the second row([1][x])
cout << " argv[1][1]:" <<endl;
cout << argv[1][1] << endl;//gets the second character of the command line
cout << " argv[1][2]:" <<endl;
cout << argv[1][2] << endl;//gets the third character of the command line
cout << " argv[1][3]:" <<endl;
cout << argv[1][3] << endl;
cout << " argv[1][4]:" <<endl;
cout << argv[1][4] << endl;
cout << " argv[2]:" <<endl;
cout << argv[2] << endl;//checks 2nd argument
cout << " argv[3]:" <<endl;
cout << argv[3] << endl;//checks 3rd argument
cout << " argv[4]:" <<endl;
cout << argv[4] << endl;//checks 4th argument
}
return 0;
}
Sunday, April 8, 2012
Break down of the Fstream walkthrough in class:
#include <fstream>
#include <iostream>
using namespace std;
int main(){
int i,j;
cout<<sizeof(i)<<endl; // the output of this line is 4
fstream f("f.bin",ios::out|ios::in|ios::binary|ios::trunc);
for(i=10;i<100;i+=10){//write 10,20,30...90
f.write((const char*)&i, sizeof(int)); //casting &i to char* because you cannot convert a char with a int because char are 1 byte whilst int are 4 bytes
//hence turning it to char* and &i will make both variable to 4 bytes (all pointers are 4 bytes)
//we put sizeof(int) because we want to write 4 bytes because we want to keep the number in the file as int not char hence keeping the right number
}
f.seekg((ios::pos_type)20);//going to position 20 in bytes(since in the file each number is an integer (4 bytes) it will shift 5 numbers (20/4)), casting 20 as a pos_type
f.read((char*)&i, sizeof(int));//reads sizeof(int)(4 bytes) and store it in i
cout<<i<<endl; // 1 mark //output is 60, even though its on position 50 it reads number after the position not the position itself
f.seekg(-(ios::off_type)sizeof(int), ios::end);//go back 4 bytes from the end of the file,at position is at 80
f.read((char*)&i, sizeof(int));//read the next 4 byte and store it in i
cout<<i<<endl; // 1 mark output: 90.
f.seekg(-(ios::off_type)sizeof(int)*3, ios::cur);//go back 12(4*3) bytes(3 ints) from the current position(90), at position(60)
f.read((char*)&i, sizeof(int));
cout<<i<<endl; // 1 mark output:70
f.seekp((ios::off_type)sizeof(int)*2, ios::beg);//go up 8 bytes from the beginnning of the file position(20)
f.write((char*)&i, sizeof(int));//write 4 bytes from &i(holding number 70 from previous read function)
f.seekp((ios::off_type)0, ios::end);//change the writing position to the end of the file
cout<<(j=f.tellp())<<endl; // 1 mark, j=36 because there are 9 integer in the file hence 36 bytes in total (4*9)
f.seekg(0);//put the reading cursor to position 0
while(f.tellg() < j){ // 1 mark, read one integer at a time until the f.tellg() is less than j
cout << "("<<f.tellg() <<")";
f.read((char*)&i, sizeof(int));
cout<<i<<"("<<f.tellg() << "), ";
}
//output: (0)10(4), (4)20(8), (8)70(12), (12)40(16), (16)50(20), (20)60(24), (24)70(28), (28)80(32), (32)90(36),
cout<<endl;
return 0;
}
#include <fstream>
#include <iostream>
using namespace std;
int main(){
int i,j;
cout<<sizeof(i)<<endl; // the output of this line is 4
fstream f("f.bin",ios::out|ios::in|ios::binary|ios::trunc);
for(i=10;i<100;i+=10){//write 10,20,30...90
f.write((const char*)&i, sizeof(int)); //casting &i to char* because you cannot convert a char with a int because char are 1 byte whilst int are 4 bytes
//hence turning it to char* and &i will make both variable to 4 bytes (all pointers are 4 bytes)
//we put sizeof(int) because we want to write 4 bytes because we want to keep the number in the file as int not char hence keeping the right number
}
f.seekg((ios::pos_type)20);//going to position 20 in bytes(since in the file each number is an integer (4 bytes) it will shift 5 numbers (20/4)), casting 20 as a pos_type
f.read((char*)&i, sizeof(int));//reads sizeof(int)(4 bytes) and store it in i
cout<<i<<endl; // 1 mark //output is 60, even though its on position 50 it reads number after the position not the position itself
f.seekg(-(ios::off_type)sizeof(int), ios::end);//go back 4 bytes from the end of the file,at position is at 80
f.read((char*)&i, sizeof(int));//read the next 4 byte and store it in i
cout<<i<<endl; // 1 mark output: 90.
f.seekg(-(ios::off_type)sizeof(int)*3, ios::cur);//go back 12(4*3) bytes(3 ints) from the current position(90), at position(60)
f.read((char*)&i, sizeof(int));
cout<<i<<endl; // 1 mark output:70
f.seekp((ios::off_type)sizeof(int)*2, ios::beg);//go up 8 bytes from the beginnning of the file position(20)
f.write((char*)&i, sizeof(int));//write 4 bytes from &i(holding number 70 from previous read function)
f.seekp((ios::off_type)0, ios::end);//change the writing position to the end of the file
cout<<(j=f.tellp())<<endl; // 1 mark, j=36 because there are 9 integer in the file hence 36 bytes in total (4*9)
f.seekg(0);//put the reading cursor to position 0
while(f.tellg() < j){ // 1 mark, read one integer at a time until the f.tellg() is less than j
cout << "("<<f.tellg() <<")";
f.read((char*)&i, sizeof(int));
cout<<i<<"("<<f.tellg() << "), ";
}
//output: (0)10(4), (4)20(8), (8)70(12), (12)40(16), (16)50(20), (20)60(24), (24)70(28), (28)80(32), (32)90(36),
cout<<endl;
return 0;
}
Saturday, April 7, 2012
Simple look at casting operator overload:
#include <iostream>
using namespace std;
class fun{
int _data;
char _char;
int* _data2;
public:
fun():_data(0){}
fun(int d):_data(d),_char('w'),_data2(0){}
fun(int d, char c):_data(d),_char(c),_data2(0){}
fun(int d, char c,int size):_data(d),_char(c){_data2 = new int[size];}
void show(){cout << "data is: " << _data << endl;
cout << "character is: "<< _char << endl;}
operator int(){cout << "inside int casting operator" << endl;//casting operator int()
return _data;}
operator char(){{cout << "inside char casting operator" << endl;//casting operator char()
return _char;}}
operator int*(){cout << "inside int* casting operator" << _data2<<endl;//casting operator int*()
return _data2;}
~fun(){
delete [] _data2;
}
};
int main (){
int x=20;
char c='d';
int* ptr(0);
fun a(5);
a.show();
x=(int)a;//calling int casting operator of class
cout << "x: " << x << endl;//output: x: 5
cout << endl;
fun stuff(10,'f',3);
stuff.show();
c = char(stuff);//calling char casting operator of class
cout << c << endl;//output: f
cout << "&ptr: " << ptr << endl;
cout << "size: " << sizeof(ptr) << endl;
ptr = (int*)stuff;//calling int* casting operator
cout << "&ptr: " << ptr << endl;//output &ptr: (same addess as _data2 in fun class)
cout << "size: " << sizeof(ptr) << endl;
delete [] ptr;
return 0;
}
//ps a little thanks to Mr. D'amico for telling me casting is a operator XD
#include <iostream>
using namespace std;
class fun{
int _data;
char _char;
int* _data2;
public:
fun():_data(0){}
fun(int d):_data(d),_char('w'),_data2(0){}
fun(int d, char c):_data(d),_char(c),_data2(0){}
fun(int d, char c,int size):_data(d),_char(c){_data2 = new int[size];}
void show(){cout << "data is: " << _data << endl;
cout << "character is: "<< _char << endl;}
operator int(){cout << "inside int casting operator" << endl;//casting operator int()
return _data;}
operator char(){{cout << "inside char casting operator" << endl;//casting operator char()
return _char;}}
operator int*(){cout << "inside int* casting operator" << _data2<<endl;//casting operator int*()
return _data2;}
~fun(){
delete [] _data2;
}
};
int main (){
int x=20;
char c='d';
int* ptr(0);
fun a(5);
a.show();
x=(int)a;//calling int casting operator of class
cout << "x: " << x << endl;//output: x: 5
cout << endl;
fun stuff(10,'f',3);
stuff.show();
c = char(stuff);//calling char casting operator of class
cout << c << endl;//output: f
cout << "&ptr: " << ptr << endl;
cout << "size: " << sizeof(ptr) << endl;
ptr = (int*)stuff;//calling int* casting operator
cout << "&ptr: " << ptr << endl;//output &ptr: (same addess as _data2 in fun class)
cout << "size: " << sizeof(ptr) << endl;
delete [] ptr;
return 0;
}
//ps a little thanks to Mr. D'amico for telling me casting is a operator XD
Break down of Fstream example in class
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class Employee{
char _name[15];
char _lastname[30];
int _empno;
double _salary;
public:
Employee(const char* name="", const char* lastname="", int empno=0, double salary=0.0){
set(name, lastname, empno, salary);
}
void set(const char* name="", const char* lastname="", int empno=0, double salary=0.0){
strcpy(_name, name);
strcpy(_lastname, lastname);
_empno = empno;
_salary = salary;
}
ostream& print(ostream& OS)const{
return OS<<"Name: "<<_name<<" "<<_lastname<<endl<<"EmpNo: "<<_empno
<<", Salary: "<<_salary;
}
virtual ~Employee(){
//print(cout)<<"is dead!!!!"<<endl;
}
};
ostream& operator<<(ostream& OS, const Employee& E){
return E.print(OS);
}
int main(){
Employee E;
ifstream file;
file.open("emp.bin",ios::binary);//open the file emp.bin, consider the stream as Binary instead of text
file.seekg((ios::off_type)0, ios::end);//set the cursor position from (0), to the end of the file(ios::end)
int loc = file.tellg();//set loc to the cursor position (tellg())
cout << sizeof(Employee) << endl;
while(loc > 0 ){//while loc is greater than zero go in here.
loc -= sizeof(Employee);//subtract loc by the size of an Employee object (72)
file.seekg((ios::pos_type)loc);//put the cursor position to loc (first time in is 288 then, 216, 144, 72, 0)
file.read((char*)&E, sizeof(Employee));//read (sizeof(Employees) = 72) of character from the current position and store it in &E, which is cast to a char*
cout<<E<<endl;
}
return 0;
}
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class Employee{
char _name[15];
char _lastname[30];
int _empno;
double _salary;
public:
Employee(const char* name="", const char* lastname="", int empno=0, double salary=0.0){
set(name, lastname, empno, salary);
}
void set(const char* name="", const char* lastname="", int empno=0, double salary=0.0){
strcpy(_name, name);
strcpy(_lastname, lastname);
_empno = empno;
_salary = salary;
}
ostream& print(ostream& OS)const{
return OS<<"Name: "<<_name<<" "<<_lastname<<endl<<"EmpNo: "<<_empno
<<", Salary: "<<_salary;
}
virtual ~Employee(){
//print(cout)<<"is dead!!!!"<<endl;
}
};
ostream& operator<<(ostream& OS, const Employee& E){
return E.print(OS);
}
int main(){
Employee E;
ifstream file;
file.open("emp.bin",ios::binary);//open the file emp.bin, consider the stream as Binary instead of text
file.seekg((ios::off_type)0, ios::end);//set the cursor position from (0), to the end of the file(ios::end)
int loc = file.tellg();//set loc to the cursor position (tellg())
cout << sizeof(Employee) << endl;
while(loc > 0 ){//while loc is greater than zero go in here.
loc -= sizeof(Employee);//subtract loc by the size of an Employee object (72)
file.seekg((ios::pos_type)loc);//put the cursor position to loc (first time in is 288 then, 216, 144, 72, 0)
file.read((char*)&E, sizeof(Employee));//read (sizeof(Employees) = 72) of character from the current position and store it in &E, which is cast to a char*
cout<<E<<endl;
}
return 0;
}
Sunday, April 1, 2012
Modified the stack list in the textbook closer to gamer point of view:
//Queue List
//First in First out FIFO
#include <iostream>
using namespace std;
class monster {
int damage;
public:
monster(int a=0):damage(a){}
int pop(){
return damage;
}
};
struct wave {
monster data;//creates a monster object when you make a wave object
wave* _next;//points to the address of a wave object
wave(const monster& a, wave* next):data(a), _next(next){}//constructor accepts a reference of a monster object and pointer that points to a wave object.
//will also initiate monster object 'a' and cast it to monster object 'data', will do the same with _next with next
};
class game {
wave* _start;
wave* _end;
public:
game(): _start(NULL), _end(NULL){}
~game (){
wave* current;
while (current = _start){
_start = _start->_next;
delete current;
}
}//~game()
void add(int d){
wave* p = new wave(d,0);//second parameter is 0 because in a Queue when you're adding it should be in the end, hence the _next value should be null
if (_start)
_end->_next=p;//if there is a _start the _end will have the new address
else
_start=p;//if there are no _start meaning this is the first one will assign the _start address to the new wave object
_end = p;//regardless if there was a value for _start or not, assign the _end to the new object
}
monster rem(){//returns a monster object
monster data;
if (_start){
wave* current=_start;
data = _start->data;//assign the _start's monster object(data, inside wave class) with the new monster object (created in this function)
_start=_start->_next;//assign the _start address to the _next _start address;
delete current;
if (!_start)//if the address of _start is NULL change the _end to NUll as well
_end=NULL;
}
return data;
}
bool empty(){return _start == NULL;}
};
int main(){
game d;//_start and _end has Null address
//Push Data onto the queue
d.add(3);
d.add(30);
d.add(10);
d.add(50);
//remove the first node
d.rem();
//pop off data off the queue
while (!d.empty())
cout << d.rem().pop() << endl;
return 0;
}
//Queue List
//First in First out FIFO
#include <iostream>
using namespace std;
class monster {
int damage;
public:
monster(int a=0):damage(a){}
int pop(){
return damage;
}
};
struct wave {
monster data;//creates a monster object when you make a wave object
wave* _next;//points to the address of a wave object
wave(const monster& a, wave* next):data(a), _next(next){}//constructor accepts a reference of a monster object and pointer that points to a wave object.
//will also initiate monster object 'a' and cast it to monster object 'data', will do the same with _next with next
};
class game {
wave* _start;
wave* _end;
public:
game(): _start(NULL), _end(NULL){}
~game (){
wave* current;
while (current = _start){
_start = _start->_next;
delete current;
}
}//~game()
void add(int d){
wave* p = new wave(d,0);//second parameter is 0 because in a Queue when you're adding it should be in the end, hence the _next value should be null
if (_start)
_end->_next=p;//if there is a _start the _end will have the new address
else
_start=p;//if there are no _start meaning this is the first one will assign the _start address to the new wave object
_end = p;//regardless if there was a value for _start or not, assign the _end to the new object
}
monster rem(){//returns a monster object
monster data;
if (_start){
wave* current=_start;
data = _start->data;//assign the _start's monster object(data, inside wave class) with the new monster object (created in this function)
_start=_start->_next;//assign the _start address to the _next _start address;
delete current;
if (!_start)//if the address of _start is NULL change the _end to NUll as well
_end=NULL;
}
return data;
}
bool empty(){return _start == NULL;}
};
int main(){
game d;//_start and _end has Null address
//Push Data onto the queue
d.add(3);
d.add(30);
d.add(10);
d.add(50);
//remove the first node
d.rem();
//pop off data off the queue
while (!d.empty())
cout << d.rem().pop() << endl;
return 0;
}
Monday, March 26, 2012
A simpler version of a Stack list with comments:
//STACK LIST
//RULE:
//LIFO (Last In, First Out), opposite of a Queue List, FIFO (First In First Out)
#include <iostream>
using namespace std;
template< class T >
class Stack {
private:
int MAX;//control how big a stack can be
int top;//the top of the stack = the data that will be giong out
T* items;//item points to a T address
public:
Stack(int size){//set the size of the stack
MAX = size;
top = -1;//-1 because when user create the object there will be no "top" data, think of this as a rack
items = new T[MAX];//set the number of item the stack can have
}
~Stack(){ delete [] items; }// deletes the entire array/stack
void push(T c){
if(full()){//check if the full function is true
cout << "Stack Full!" << endl;
//return 1;
}
items[++top] = c;//if the stack istn full will put the "data" in the first array[++top]
}
T pop(){
if(empty()){
cout << "Stack Empty!" << endl;
//return 1;
}
return items[top--];//reason why you have top= -1 in the constructor;
//reduce redundant variable in this function. without top=-1, will need to make a variable that holds the item data
}
int empty(){ return top == -1; }
int full(){ return top+1 == MAX; }
};
int main(){
Stack<char> st(10);
//the letters 'A' - 'J'
for(int i = 65; i < 75; i++)
st.push(i);//as the I increment, so does the top
//remove all the data
for(int j = 0; j < 11; j++)
cout << st.pop() << endl;//as the J increment top in the the object decrements hence getting the "stack" link list (taking from the last one in first)
return 0;
}
//STACK LIST
//RULE:
//LIFO (Last In, First Out), opposite of a Queue List, FIFO (First In First Out)
#include <iostream>
using namespace std;
template< class T >
class Stack {
private:
int MAX;//control how big a stack can be
int top;//the top of the stack = the data that will be giong out
T* items;//item points to a T address
public:
Stack(int size){//set the size of the stack
MAX = size;
top = -1;//-1 because when user create the object there will be no "top" data, think of this as a rack
items = new T[MAX];//set the number of item the stack can have
}
~Stack(){ delete [] items; }// deletes the entire array/stack
void push(T c){
if(full()){//check if the full function is true
cout << "Stack Full!" << endl;
//return 1;
}
items[++top] = c;//if the stack istn full will put the "data" in the first array[++top]
}
T pop(){
if(empty()){
cout << "Stack Empty!" << endl;
//return 1;
}
return items[top--];//reason why you have top= -1 in the constructor;
//reduce redundant variable in this function. without top=-1, will need to make a variable that holds the item data
}
int empty(){ return top == -1; }
int full(){ return top+1 == MAX; }
};
int main(){
Stack<char> st(10);
//the letters 'A' - 'J'
for(int i = 65; i < 75; i++)
st.push(i);//as the I increment, so does the top
//remove all the data
for(int j = 0; j < 11; j++)
cout << st.pop() << endl;//as the J increment top in the the object decrements hence getting the "stack" link list (taking from the last one in first)
return 0;
}
Tuesday, March 20, 2012
Wednesday, March 14, 2012
March 12, Lab
printing bitrate
#include <iostream>
using namespace std;
char* bit(unsigned int);
char isOn(unsigned int, unsigned int);
int main(){
int test=10;
cout << sizeof(int) << endl;
cout << sizeof(test) << endl;
cout << bit(test) << endl;
return 0;
}
char* bit(unsigned int i){
static char binary[31]; //int is 4 bytes meaning 32 bits
int num;
int c;
for(c=sizeof(i)*8-1,num=0;c>=0,num < sizeof(i)*8;c--,num++)
binary[num]=(isOn(i,c));//num increments the array of binary while c looks at every bitrate one by one
return binary;
}
char isOn(unsigned int num, unsigned int bitNo){
unsigned int m=1 << bitNo;
if ((num & m) != 0)
return '1';
else
return '0';
}
printing bitrate
#include <iostream>
using namespace std;
char* bit(unsigned int);
char isOn(unsigned int, unsigned int);
int main(){
int test=10;
cout << sizeof(int) << endl;
cout << sizeof(test) << endl;
cout << bit(test) << endl;
return 0;
}
char* bit(unsigned int i){
static char binary[31]; //int is 4 bytes meaning 32 bits
int num;
int c;
for(c=sizeof(i)*8-1,num=0;c>=0,num < sizeof(i)*8;c--,num++)
binary[num]=(isOn(i,c));//num increments the array of binary while c looks at every bitrate one by one
return binary;
}
char isOn(unsigned int num, unsigned int bitNo){
unsigned int m=1 << bitNo;
if ((num & m) != 0)
return '1';
else
return '0';
}
Monday, March 12, 2012
Wednesday, February 1, 2012
Thursday, January 26, 2012
Friday, January 20, 2012
Monday, January 16, 2012
Thursday, January 12, 2012
Tuesday, January 10, 2012
Subscribe to:
Posts (Atom)