Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 12th, 2010, 01: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
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.


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 04:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.