![]() |
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 |
Code for Chapter 3 Exercise problem #6
Code:
// Solu3_6.cpp : main project file. |
| All times are GMT -4. The time now is 06:59 AM. |
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.