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;