Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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 Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2012, 12:11 AM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default Chapter 3 exercise 6

In the book for chapter 3 exercises the author asks:
"Write a CLR console program that defines a string (as type String^) and then analyzes the characters in the string to discover the number of uppercase letters, the number of lowercase letters, the number of non-alphabetic characters, and the total number of characters in the string."
I noticed that the downloaded code solution is finding "vowels and consonants"
I have written code to solve the exercise in the book.
code
// Solu3_6.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
int caps = 0;
int small = 0;
int nalpha = 0;
int totalchar = 0;

String^ string = L"In 1978, Lasse Nielsen\'s film \"Du er ikke alene\" was released.";

for each(wchar_t ch in string)
{
++totalchar;
if(Char::IsLetter(ch))
{
if(Char::IsUpper(ch))
++caps;
else
++small;

}

if(Char::IsDigit(ch))
++nalpha;
if(Char::IsPunctuation(ch))
++nalpha;

}
Console::WriteLine(string);

Console::WriteLine(L"\nThe total of capitals is {0} and small letters is {1}.", caps, small);

Console::WriteLine(L"The total non-alphabetic is {0} and total characters is {1}.",nalpha, totalchar);
return 0;
}
/code
  #2 (permalink)  
Old February 10th, 2012, 09:10 PM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default Code for Chapter 3 Exercise problem #6

Code:
// Solu3_6.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
	int caps = 0;
	int small = 0;
	int nalpha = 0;
	int totalchar = 0;

	String^ string = L"In 1978, Lasse Nielsen\'s film \"Du er ikke alene\" was released.";

	for each(wchar_t ch in string)
	{
		++totalchar;
		if(Char::IsLetter(ch))
		{
			if(Char::IsUpper(ch))
				++caps;
			else
				++small;

		}

		if(Char::IsDigit(ch))
			++nalpha;
		if(Char::IsPunctuation(ch))
			++nalpha;

	}
	Console::WriteLine(string);

	Console::WriteLine(L"\nThe total of capitals is {0} and small letters is {1}.", caps, small);

	Console::WriteLine(L"The total non-alphabetic is {0} and total characters is {1}.",nalpha, totalchar);
	return 0;
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Chapter 2 Exercise 2 rolndd BOOK: Ivor Horton's Beginning Visual C++ 2010 2 July 12th, 2011 01:58 PM
Exercise 6 for chapter 2 scooter5 BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 3 August 27th, 2010 11:24 AM
Chapter 2 Exercise #5 yowzer14 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 August 26th, 2010 12:33 AM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
chapter 9 exercise michaelcode BOOK: Beginning ASP.NET 1.0 1 April 9th, 2006 03:56 PM



All times are GMT -4. The time now is 03:14 PM.


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