Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,675 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,507 people online right now. Registration is fast and FREE... Join Now!




Finding Lower Case Letters

2 Pages V  1 2 >  
Reply to this topicStart new topic

Finding Lower Case Letters

ginobili
post 17 Nov, 2005 - 03:09 PM
Post #1


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


I have an assignement due tonight i have done the best i can but i still need a bit more if youcould help that will be great


Attached File(s)
Attached File  Question1.zip ( 14.19k ) Number of downloads: 54
User is offlineProfile CardPM

Go to the top of the page


Nova Dragoon
post 17 Nov, 2005 - 03:18 PM
Post #2


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,124



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


Please read the Guidelines first before posting

but, because Im nice:

//write a function called isLowerCase that has one parameter of type char
//and returns a bool: true if the character in the parameter is a
//lowercase letter and false if not.
//Use the function to count the number of lower case letters in
//the Declaration of Independence. Print out the results.
//Also determine the percentage of lower case letters in the
//the Declaration of Independence. Print out the results.

CODE

#include <iostream>
#include "GlobalTextString.h"
                                                                               
                                                                               
int main ()
{
  //text characters (type: char) are actually stored as numbers
  //For example
  std::cout << " a is " << static_cast<int>('a') << std::endl;
  std::cout << " b is " << static_cast<int>('b') << std::endl;
  std::cout << " c is " << static_cast<int>('c') << std::endl;
  std::cout << " down to"  << std::endl;
  std::cout << " z is " << static_cast<int>('z') << std::endl;
  //so we could say
  char lowerCaseA = 97;
  char lowerCaseZ = 122;
  std::cout << " lowerCaseA = " << lowerCaseA << " or "
     << static_cast<int>(lowerCaseA) << std::endl;
  std::cout << " lowerCaseZ = " << lowerCaseZ << " or "
     << static_cast<int>(lowerCaseZ) << std::endl;
  //thus if a character's numeric value is greater or equal to 97
  //and less than or equal to 122 it must be a lower case letter.
  //so....
  char ch = 107; // 'k'
  std::cout << static_cast<int>('a')  << " <= "
            << static_cast<int>(ch)   << " <= "
            << static_cast<int>('z')  << std::endl;
  //or
  std::cout << static_cast<char>(97)  << " <= "
            << ch   << " <= "
            << static_cast<char>(122)  << std::endl;
                                                                               
  //////////
  //The string in the included file contains the text of
  //the Declaration of Independence.
  std::string declaration = DeclarationOfIndependence; //copy locally
  //Printing out the string one character at a time
  int place = 0;
  while( place < declaration.length() )
  {
     ch = declaration.at(place);
     std::cout << ch;
     place++;
  }
  return 0;
}



And the header file:
CODE


#include <string>


std::string str1 = "The Declaration of Independence of The United States of America\n\
\n\
\n\
                       IN CONGRESS, July 4, 1776\n\
\n\
\n\
The unanimous Declaration of the thirteen united States of America\n\
\n\
When in the Course of human events, it becomes necessary for one people to\n\
dissolve the political bands which have connected them with another, and\n\
to assume, among the Powers of the earth, the separate and equal station\n\
to which the Laws of Nature and of Nature's God entitle them, a decent\n\
respect to the opinions of mankind requires that they should declare the\n\
causes which impel them to the separation.\n\
\n\
We hold these truths to be self-evident, that all men are created equal,\n\
that they are endowed by their Creator with certain unalienable Rights,\n\
that among these are Life, Liberty, and the pursuit of Happiness.--That to\n\
secure these rights, Governments are instituted among Men, deriving their\n\
just powers from the consent of the governed,--That whenever any Form of\n\
Government becomes destructive of these ends, it is the Right of the\n\
People to alter or to abolish it, and to institute new Government, laying\n\
its foundation on such principles and organizing its powers in such form,\n\
as to them shall seem most likely to effect their Safety and Happiness.\n\
Prudence, indeed, will dictate that Governments long established should\n\
not be changed for light and transient causes; and accordingly all\n\
experience hath shown, that mankind are more disposed to suffer, while\n\
evils are sufferable, than to right themselves by abolishing the forms to\n\
which they are accustomed. But when a long train of abuses and\n\
usurpations, pursuing invariably the same Object evinces a design to\n\
reduce them under absolute Despotism, it is their right, it is their duty,\n\
to throw off such Government, and to provide new Guards for their future\n\
security.--Such has been the patient sufferance of these Colonies; and such\n\
is now the necessity which constrains them to alter their former Systems\n\
of Government. The history of the present King of Great Britain is a";

std::string str2 = "history of repeated injuries and usurpations, all having in direct object\n\
the establishment of an absolute Tyranny over these States. To prove this,\n\
let Facts be submitted to a candid world.\n\
\n\
     He has refused his Assent to Laws, the most wholesome and necessary\n\
     for the public good.\n\
\n\
     He has forbidden his Governors to pass Laws of immediate and\n\
     pressing importance, unless suspended in their operation till his\n\
     Assent should be obtained; and when so suspended, he has utterly\n\
     neglected to attend to them.\n\
\n\
     He has refused to pass other Laws for the accommodation of large\n\
     districts of people, unless those people would relinquish the right\n\
     of Representation in the Legislature, a right inestimable to them\n\
     and formidable to tyrants only.\n\
\n\
     He has called together legislative bodies at places unusual,\n\
     uncomfortable, and distant from the depository of their Public\n\
     Records, for the sole purpose of fatiguing them into compliance with\n\
     his measures.\n\
\n\
     He has dissolved Representative Houses repeatedly, for opposing with\n\
     manly firmness his invasions on the rights of the people.\n\
\n\
     He has refused for a long time, after such dissolutions, to cause\n\
     others to be elected; whereby the Legislative Powers, incapable of\n\
     Annihilation, have returned to the People at large for their\n\
     exercise; the State remaining in the mean time exposed to all the\n\
     dangers of invasion from without, and convulsions within.\n\
\n\
     He has endeavoured to prevent the population of these States; for\n\
     that purpose obstructing the Laws of Naturalization of Foreigners;\n\
     refusing to pass others to encourage their migration hither, and\n\
     raising the conditions of new Appropriations of Lands.\n\
\n\
     He has obstructed the Administration of Justice, by refusing his\n\
     Assent to Laws for establishing Judiciary Powers.\n\
\n";
std::string str3 = "      He has made judges dependent on his Will alone, for the tenure of\n\
     their offices, and the amount and payment of their salaries.\n\
\n\
     He has erected a multitude of New Offices, and sent hither swarms of\n\
     Officers to harass our People, and eat out their substance.\n\
\n\
     He has kept among us, in times of peace, Standing Armies without the\n\
     Consent of our legislatures.\n\
\n\
     He has affected to render the Military independent of and superior\n\
     to the Civil Power.\n\
\n\
     He has combined with others to subject us to a jurisdiction foreign\n\
     to our constitution, and unacknowledged by our laws; giving his\n\
     Assent to their Acts of pretended legislation:\n\
\n\
     For quartering large bodies of armed troops among us:\n\
\n\
     For protecting them, by a mock Trial, from Punishment for any\n\
     Murders which they should commit on the Inhabitants of these States:\n\
\n\
     For cutting off our Trade with all parts of the world:\n\
\n\
     For imposing taxes on us without our Consent:\n\
\n\
     For depriving us, in many cases, of the benefits of Trial by Jury:\n\
\n\
     For transporting us beyond Seas to be tried for pretended offences:\n\
\n\
     For abolishing the free System of English Laws in a neighbouring\n\
     Province, establishing therein an Arbitrary government, and\n\
     enlarging its Boundaries so as to render it at once an example and\n\
     fit instrument for introducing the same absolute rule into these\n\
     Colonies:\n\
\n\
     For taking away our Charters, abolishing our most valuable Laws, and\n\
     altering fundamentally the Forms of our Governments:\n\
\n\
     For suspending our own Legislatures, and declaring themselves\n\
     invested with Power to legislate for us in all cases whatsoever.\n\
\n\
     He has abdicated Government here, by declaring us out of his\n\
     Protection and waging War against us.\n\
\n\
     He has plundered our seas, ravaged our Coasts, burnt our towns, and\n\
     destroyed the lives of our people.\n\
\n";

std::string str4 = "      He is at this time transporting large armies of foreign mercenaries\n\
     to compleat the works of death, desolation and tyranny, already\n\
     begun with circumstances of Cruelty & perfidy scarcely paralleled in\n\
     the most barbarous ages, and totally unworthy of the Head of a\n\
     civilized nation.\n\
\n\
     He has constrained our fellow Citizens taken Captive on the high\n\
     Seas to bear Arms against their Country, to become the executioners\n\
     of their friends and Brethren, or to fall themselves by their Hands.\n\
\n\
     He has excited domestic insurrections amongst us, and has\n\
     endeavoured to bring on the inhabitants of our frontiers, the\n\
     merciless Indian Savages, whose known rule of warfare, is an\n\
     undistinguished destruction of all ages, sexes and conditions.\n\
\n\
In every stage of these Oppressions We have Petitioned for Redress in the\n\
most humble terms: Our repeated Petitions have been answered only by\n\
repeated injury. A Prince, whose character is thus marked by every act\n\
which may define a Tyrant, is unfit to be the ruler of a free People.\n\
\n\
Nor have We been wanting in attention to our Brittish brethren. We have\n\
warned them from time to time of attempts by their legislature to extend\n\
an unwarrantable jurisdiction over us. We have reminded them of the\n\
circumstances of our emigration and settlement here. We have appealed to\n\
their native justice and magnanimity, and we have conjured them by the\n\
ties of our common kindred to disavow these usurpations, which would\n\
inevitably interrupt our connections and correspondence. They too have\n\
been deaf to the voice of justice and of consanguinity. We must,\n\
therefore, acquiesce in the necessity, which denounces our Separation, and\n\
hold them, as we hold the rest of mankind, Enemies in War, in Peace\n\
Friends.\n\
\n";

std::string str5 = "We, therefore, the Representatives of the United States of America, in\n\
General Congress, Assembled, appealing to the Supreme Judge of the world\n\
for the rectitude of our intentions, do, in the Name, and by the Authority\n\
of the good People of these Colonies, solemnly publish and declare, That\n\
these United Colonies are, and of Right ought to be Free and Independent\n\
States; that they are Absolved from all Allegiance to the British Crown,\n\
and that all political connection between them and the State of Great\n\
Britain, is and ought to be totally dissolved; and that as Free and\n\
Independent States, they have full Power to levy War, conclude Peace,\n\
contract Alliances, establish Commerce, and to do all other Acts and\n\
Things which Independent States may of right do. And for the support of\n\
this Declaration, with a firm reliance on the Protection of Divine\n\
Providence, we mutually pledge to each other our Lives, our Fortunes and\n\
our sacred Honor.";

std::string DeclarationOfIndependence = str1 + str2 + str3 + str4 + str5;
User is online!Profile CardPM

Go to the top of the page

Dark_Nexus
post 17 Nov, 2005 - 03:47 PM
Post #3


or something bad...real bad.

Group Icon
Joined: 2 May, 2004
Posts: 1,309



Thanked 1 times

Dream Kudos: 625
My Contributions


i am actually stunned! that nearly deserves some kudos.
User is offlineProfile CardPM

Go to the top of the page

ginobili
post 17 Nov, 2005 - 03:55 PM
Post #4


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


Come on guys we all went trough it one day or onother you all act like saints, everyone get a day where he needs a break this is mine.
I am no expert in programming but i kind of like it i just got slammed with this assignement and need some help. I have another one for the lucky person who fixes the first.

Just joking

If you think that you are above this forgive my intrudance to this group you guys were always helpfull.

thanks again

Ginobili.
User is offlineProfile CardPM

Go to the top of the page

Mrafcho001
post 17 Nov, 2005 - 04:10 PM
Post #5


D.I.C Addict

Group Icon
Joined: 1 Nov, 2005
Posts: 753



Thanked 5 times

Dream Kudos: 120
My Contributions


Its very simple. Just create a function as Nova Dragoon said that accepts one char at a time, cast the char to an int and check if its between the range of 65 and 90, if it is within the range then its a capital letter, return false, and if it is not within the range than its a lower case, return true.

do a while loop in the main func, that is like the one you already have in the code. Declare a variable and set it to 0, and add 1 to it everytime the loop runs. The loop conditions would be while(var <= string.size()). as the one in the code.

Also have another variable that everytime the function returns false it adds one to it. After the loop is done, you should have the count of the capital letters in the string.

Subtract that number from the string size and you have the count of the lower case letters in the string.


As simple as that.
User is offlineProfile CardPM

Go to the top of the page

ginobili
post 17 Nov, 2005 - 04:13 PM
Post #6


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


Thank you guys!
Thank you very much!
I am loving C++ more and more now.

Ginobili.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 17 Nov, 2005 - 04:18 PM
Post #7


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


QUOTE(ginobili @ 17 Nov, 2005 - 07:52 PM)

If you think that you are above this forgive my intrudance to this group you guys were always helpfull.

thanks again

Ginobili.

Hi Ginobili,

There was certainly no intent to insult you...the goal of the site (when it comes to scholastic endeavors) is to guide users working on assignments, not write source code for them. If someone is simply given the code, they do not learn anything.

Now you mentioed that you were having trouble, but neglected to mention what that trouble was. Can you please describe how the program is not behaving as you expected?
User is online!Profile CardPM

Go to the top of the page

ginobili
post 17 Nov, 2005 - 04:28 PM
Post #8


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


I can't quite grab how to use the bool function. I have problem with the return???
can you help.
Thank you
Ginobili
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 17 Nov, 2005 - 04:30 PM
Post #9


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


Which function are you referring to? bool in and of itself is not a function.
User is online!Profile CardPM

Go to the top of the page

ginobili
post 17 Nov, 2005 - 04:34 PM
Post #10


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


this function: LowerCase that has one parameter of type char
and returns a bool: true if the character in the parameter is a
lowercase letter and false if not.
How will i implement it

I knowthat it will be something like this:

bool LowerCase(char a)
{
this is what i am confused with.
}
User is offlineProfile CardPM

Go to the top of the page

ginobili
post 17 Nov, 2005 - 04:51 PM
Post #11


New D.I.C Head

*
Joined: 5 Nov, 2005
Posts: 46


My Contributions


how will iimplement this function :

[CODE]
bool LowerCase(char a)
{

if ( a >= 97 && a <= 122 )
return true;
else
return false;
}

to to count the number of lower case letters in the document.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 17 Nov, 2005 - 05:02 PM
Post #12


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


That function will serve to determine if a character is lower or upper case...is it looping through the text that you are having a problem with?
User is online!Profile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 11/20/08 07:24AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month