Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // test
- //
- // Created by MacBook on 18.04.2020.
- // Copyright © 2020 MacBook. All rights reserved.
- //
- #include <iostream>
- using namespace std;
- void allEnteringSymbols()
- {
- //deleting all entering symbols
- char baby[32];
- cout << "Please enter a string" << endl;
- cin >> baby;
- char symbolToDelete;
- cout << "What symbol to delete? Enter please a number " << endl;
- cin >> symbolToDelete;
- int stringCounter = 0;
- while (*(baby + stringCounter) != '\0') {
- stringCounter++;
- }
- for (int i = 0; i < stringCounter; i++) {
- if(baby[i] == symbolToDelete)
- {
- baby[i] = '\0';
- }
- }
- for (int i = 0; i < stringCounter; i++) {
- cout << baby[i] << endl;
- }
- }
- //--------------
- //symbol to delete
- void symbolToDelete()
- {
- char string[32];
- int numberToDelete = 0;
- cout << "Please enter a string" << endl;
- cin >> string;
- cout << "Please enter what symbol to delete? Enter a number" << endl;
- cin >> numberToDelete;
- string[numberToDelete] = ' ';
- cout << string;
- }
- //entering a symbol to string by a number
- void enteringSymbol ()
- {
- char string[] = "Hello World";
- int positionNumber = 0;
- char symbolToChange;
- cout << "Please enter the position number" << endl;
- cin >> positionNumber;
- cout << "Please enter a symbol to change" << endl;
- cin >> symbolToChange;
- string[positionNumber] = symbolToChange;
- cout << string << endl;
- }
- void changingSymbols ()
- {
- char string[32];
- char symbolToChange = '!';
- int stringCounter = 0;
- cout << "Please enter a string" << endl;
- cin >> string;
- while (string[stringCounter] != '\0') {
- if (string[stringCounter] == '.')
- {
- string[stringCounter] = symbolToChange;
- }
- stringCounter++;
- }
- cout << string << endl;
- }
- void symbolCounter()
- {
- char string[32];
- char symbolToRescue;
- int symbolCounter = 0;
- cout << "Please enter a string" << endl;
- cin >> string;
- cout << "Please enter the symbol to find" << endl;
- cin >> symbolToRescue;
- for (int i = 0; i < strlen(string); i++) {
- if (string[i] == symbolToRescue) {
- symbolCounter++;
- }
- }
- cout << "How many times the symbol in the string -> " << symbolCounter << endl;
- }
- //получаем длину строки
- int GetStringSize(char *str)
- {
- int counter = 0;
- while (str[counter] != '\0') {
- counter++;
- }
- return counter;
- }
- //функция проверки на буквы
- bool IsCharSymbol(char Symbol)
- {
- short symb = Symbol;
- if (((symb > 64) && (symb < 91)) || ((symb > 96) && (symb < 123))) {
- return true;
- }
- return false;
- }
- //функция проверки на цифры
- bool IsCharNumber(char Number)
- {
- short symb = Number;
- if ( symb > 47 && symb < 58) {
- return true;
- }
- return false;
- }
- int main(int argc, const char * argv[]) {
- allEnteringSymbols();
- enteringSymbol();
- changingSymbols();
- symbolCounter();
- char* str = new char [128];
- cin.getline(str, 128);
- int StringLength = GetStringSize(str);//получили длину
- int LeterCounter = 0;
- int NumberCounter = 0;
- int OtherSymbols = 0;
- for (int i = 0; i < StringLength; i++) {//идем по стрингу
- if (IsCharSymbol(str[i])) {
- LeterCounter++;
- }else if(IsCharNumber(str[i]))
- {
- NumberCounter++;
- } else{
- OtherSymbols++;
- }
- }
- cout << "Letter quantity is " << LeterCounter << endl;
- cout << "Number quantity is " << NumberCounter << endl;
- cout << "OtherSymbols quantity is " << OtherSymbols << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement