#include <cmath> #include <iostream> #include <cstdlib> #include <cstring> #include <fstream> #include <string> #include<stdio.h> #include <string.h> using namespace std; int doubledelete(); int numberwordsinstring(); int reversewloop(); int main(); int reverse(); int asciistring(); // Part 1 //1. Find Number in Middle and return it std::string middleCharacters(const std::string &str) { if (str.length() <= 0) return ""; // For an empty string, return an empty string (customize this as desired) return str.substr((str.length() - 1) / 2, 2 - str.length() % 2); } //Part 2 Repeater std::string repeat( const std::string &word, int times ) { std::string result ; result.reserve(times*word.length()); // avoid repeated reallocation for ( int a = 0 ; a < times ; a++ ) result += word ; return result ; } int main( ) { std::cout << repeat( "Ha" , 5 ) << std::endl ; return 0 ; } // Part 3 // loop through the string looking for ". " // when ". " is found, delete one of the spaces // Repeat process until ". " is not found. string forceSingleSpaces1 (string str) { size_t found(str.find(". ")); while (found !=string::npos){ str.erase(found+1,1); found = str.find(". "); } return str; } int doubledelete(){ cout << forceSingleSpaces1("sentence1. sentence2. end. ") << endl; return EXIT_SUCCESS; } // Part 4 number of words in string int numberwordsinstring() { int i, numspaces; char nextChar; string msg; numspaces=1; cout << "Type in a string\n"; getline(cin, msg); // checks each character in the string for (i=0; i<int(msg.length()); i++) { nextChar = msg.at(i); // gets a character if (isspace(msg[i])) numspaces++; } cout << "\nThere are " << numspaces << " words in this string."; cin.ignore(); return 0; } // Part 6 Reverse char STOP[265]; void reverse(char* a)// error: initializing argument 1 of ‘int reverse(char*)’ [-fpermissive] { int c = strlen(a) - 1; for (; c >= 0; c--) { cout << a[c]; } } int reversewloop() { cout<<"Please digit an input to be reversed: "<<endl; cin.getline(STOP,265); reverse(STOP); //error: invalid conversion from ‘char’ to ‘char*’ // [-fpermissive] system("pause"); return 0; } //7. Reverse no loops int complexReverseString(string userInput) { string source(userInput); string target( source.rbegin(), source.rend() ); cout << "The reversed string is " << target << endl; return 0; } int reverse() { ifstream input; string forward; cout << "Please enter a string to see its reverse. (Will display reverse twice)" << endl; input.open("information.txt"); cin >> forward; //reverseString(forward, findStringSize(forward)); a function I'm not actually calling input >> forward; complexReverseString(forward); input.close(); system ("pause"); } //8 Ascii //C program to accept a string from user and //display its ascii value and //then display sum of all ascii value of strings int asciistring() { char String[100]; int Sum,Index; Sum=0; //Sum is initially zero printf("Enter the string:\n"); gets(String); //Accept String from User for(Index=0;Index<strlen(String);Index++) { Sum+=(String[Index]); //Adds (the ASCII values of) the String characters. } printf("The sum is %d\n",Sum); //Printing it as %d gives the equivalent ASCII value. return 0; } //9 acsiiArraysum //10 getputI still have three more functions to put in there but am I going about this the right way?
guess my question should be am I declaring and calling my prototypes right if that is the right terminology