Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 12th, 2010, 12:09 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 3 - Exercise 4 - Solution gives no output

I did not find out how to write this application/exercise and decided to peek at the code/answer available for download. But when running/debugging the code provided for a solution nothing is ouput to the command line.

Below is the code/solution which did'nt work. Even if it should work, is there a specific reason for the hexadecimal values to be set with the values they were or could you set them to whatever you prefer?


// Soln3_4.cpp

/* This is a good test of your ability to work with hexadecimal values
and individual bits. Remember, each hexadecimal digit defines 4 bits.
There are six different combinations for the file open mode,
read, write or append combined with each of text and binary modes.
You can therefore set modes in a loop with six iterations.
*/

#include <iostream>
using std::cout;

const int text = 0x01;
const int binary = 0x02;

const int read = 0x10;
const int write = 0x20;
const int append = 0x40;

int main()
{
int mode = 0; // File open mode
for(int modeSelect = 0 ; modeSelect<6 ; modeSelect++)
{
// Set a different mode for each loop iteration
switch(modeSelect)
{
case 0:
mode = text | read;
break;
case 1:
mode = text | write;
break;
case 2:
mode = text | append;
break;
case 3:
mode = binary | read;
break;
case 4:
mode = binary | write;
break;
case 5:
mode = binary | append;
break;
}

// Determine the mode that is set and output it
if (mode & text)
cout << "mode is (text,";
else if (mode & binary)
cout << "mode is (binary,";

if (mode & read)
cout << "read)\n";
else if (mode & write)
cout << "write)\n";
else if (mode & append)
cout << "append)\n";
}

return 0;
}
  #2 (permalink)  
Old April 19th, 2010, 08:06 AM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to meteormatt Send a message via Yahoo to meteormatt Send a message via Skype™ to meteormatt
Default

Quote:
Originally Posted by Cryotic View Post
I did not find out how to write this application/exercise and decided to peek at the code/answer available for download. But when running/debugging the code provided for a solution nothing is ouput to the command line.

Below is the code/solution which did'nt work. Even if it should work, is there a specific reason for the hexadecimal values to be set with the values they were or could you set them to whatever you prefer?


// Soln3_4.cpp

/* This is a good test of your ability to work with hexadecimal values
and individual bits. Remember, each hexadecimal digit defines 4 bits.
There are six different combinations for the file open mode,
read, write or append combined with each of text and binary modes.
You can therefore set modes in a loop with six iterations.
*/

#include <iostream>
using std::cout;

const int text = 0x01;
const int binary = 0x02;

const int read = 0x10;
const int write = 0x20;
const int append = 0x40;

int main()
{
int mode = 0; // File open mode
for(int modeSelect = 0 ; modeSelect<6 ; modeSelect++)
{
// Set a different mode for each loop iteration
switch(modeSelect)
{
case 0:
mode = text | read;
break;
case 1:
mode = text | write;
break;
case 2:
mode = text | append;
break;
case 3:
mode = binary | read;
break;
case 4:
mode = binary | write;
break;
case 5:
mode = binary | append;
break;
}

// Determine the mode that is set and output it
if (mode & text)
cout << "mode is (text,";
else if (mode & binary)
cout << "mode is (binary,";

if (mode & read)
cout << "read)\n";
else if (mode & write)
cout << "write)\n";
else if (mode & append)
cout << "append)\n";
}

return 0;
}
There may be have some errors.
  #3 (permalink)  
Old April 19th, 2010, 08:57 AM
Authorized User
 
Join Date: Feb 2010
Location: MA
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I ran the solution code, and saw output which appears to be as expected.

The hex values need to be such that {text,binary} and {read,write,append} may each be uniquely decoded from one int value. The values used in the solution satisfy that requirement.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
My solution to exercise 6, on ch.2 - help rjm BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 July 28th, 2010 05:50 PM
Chapter 13 Exercise 3 solution firblazer BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 19th, 2008 07:16 AM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM
exercise solution uddessjava Java Basics 1 December 29th, 2005 03:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM



All times are GMT -4. The time now is 12:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.