1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
void charLength(string*, string*, string*, string, string, string); //Gets the length of the string lines.
void reverseString(string*, string*, string*); //Reverses the String lines.
void wordCount(string*, string*, string*); //Counts the number of words in the string lines.
//------------------//
int main()
{
//-----------------------------Data to get string information--------------------//
string line01, line02, line03;
ifstream inFile;
inFile.open("testdata.txt"); //Opens test .txt file
int length1, length2, length3, totalLength, len1, len2, len3; //Hold the length of the strings
getline(inFile, line01); //
getline(inFile, line02); //Gets the lines of the .txt file.
getline(inFile, line03); //
string *ptr1 = &line01; //
string *ptr2 = &line02; //Copies pointers to similar variables
string *ptr3 = &line03; //
//--------------------------------------------------------------------------------//
//--------------------Functions---------------------------------------------------//
charLength(ptr1, ptr2, ptr3, line01, line02, line03); //Get length of string lines.
reverseString(ptr1, ptr2, ptr3); //Reverses the strings.
//-------------------------------------------------------------------------------//
int choice, funChoice;
//cout << "---------MENU---------" << endl;
//cout << endl << endl;
//cout << "1.) View data by string." << endl;
//cout << "2.) View data by function." << endl;
//cout << "3.) END PROGRAM" << endl;
}
void charLength(string *ptr1, string *ptr2, string *ptr3, string line01, string line02, string line03)
{
int length1, length2, length3;
cout << "-***********************NUMBER OF CHARACTERS*********************************- " << endl;
//-----------------------------------Gets string lengths below------------------------------------------------------//
for(int i = 0; i != line01.length(); i++) //Determines isalpha string length for line 1
{
if(isalpha(line01[i]))
{
length1++;
}
}
for(int i = 0; i != line02.length(); i++) //Determines isalpha string length for line 2
{
if(isalpha(line02[i]))
{
length2++;
}
}
for(int i = 0; i != line03.length(); i++) //Determines isalpha string length for line 3
{
if(isalpha(line03[i]))
{
length3++;
}
}
//-----------------------------------------------------------------------------------------//
cout << "The length of line 1: " << length1 + 1 << endl; //
cout << "The length of line 2: " << length2 + 1 << endl; //outputs the length of lines 1-3 of the .txt file
cout << "The length of line 3: " << length3 + 1 << endl; //
cout << endl << endl;
}
void reverseString(string *ptr1, string *ptr2, string *ptr3) //Function that reverses the strings from the .txt file.
{
ifstream inFile;
inFile.open("testdata.txt"); //Opens test .txt file
cout << "-*********************REVERSES STRINGS***************************- " << endl;
cout << "Here is the String the correct way: " << endl << endl;
cout << *ptr1 << endl; //
cout << *ptr2 << endl; //Outputs the three strings the correct way.
cout << *ptr3 << endl << endl; //
//---------------------------reverses the strings below-------------------------//
int ptrLen1, ptrLen2, ptrLen3;
string one = *ptr1; //
string two = *ptr2; //Reads pointers into individual regular strings.
string three = *ptr3;//
const int size = 300;
char newArray1[size];//
char newArray2[size];//New Arrays to hold strings without spaces and punctuation.
char newArray3[size];//
int arraySize1 = 0;
int arraySize2 = 0;
int arraySize3 = 0;
char revArray1[size];
char revArray2[size];
char revArray3[size];
int j = 0;
//First New Array
for(int i = 0; i < one.length(); i++)
{
if (isalpha(one.at(i)))
{
newArray1[j] = one.at(i);
cout << newArray1[j];
arraySize1++;
revArray1[j] = newArray1[j];
}
}
cout << endl;
//Second New Array
for(int i = 0; i < two.length(); i++)
{
if (isalpha(two.at(i)))
{
newArray2[j] = two.at(i);
cout << newArray2[j];
arraySize2++;
}
}
cout << endl;
//Third New Array
for(int i = 0; i < three.length(); i++)
{
if (isalpha(three.at(i)))
{
newArray3[j] = three.at(i);
cout << newArray3[j];
arraySize3++;
}
}
//-----------------------------Determines if strings are Palindromes below--------------------------------------//
}
|