Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. /*
  2.  * File:   main.cpp
  3.  * Author: Athanasios Pazos
  4.  *
  5.  * Created on December 11, 2019, 12:47 PM
  6.  */
  7.  
  8. #include <cstdlib>
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. int sum(int t[], int size) {
  14.     int s = 0;
  15.     for (int i = 0; i < size; i++) {
  16.         s += t[i];
  17.     }
  18.     return s;
  19. }
  20.  
  21.  
  22. bool allTrue(bool t[], int size) {
  23.     bool check = true;
  24.     for(int i = 0; i < size && check = true; i++) {
  25.         if (t[i] == 0) {
  26.             check = false;
  27.         }
  28.     }
  29.     return check;
  30. }
  31.  
  32.  
  33. int replace(char chrs[], int size, char oldChar, char newChar) {
  34.     int counter = 0;
  35.     for (int i = 0; i < size; i++) {
  36.         if (chrs[i] == oldChar) {
  37.             chrs[i] = newChar;
  38.             counter++;
  39.         }
  40.     }
  41. }
  42.  
  43. int main(int argc, char** argv) {
  44.     cout << "ArraysApp" << endl << "by Athanasios Pazos" << endl << "~~~~~~~~~~~~~~~~~~~" << endl;
  45.    
  46.    
  47.     //1
  48.    
  49.     /*
  50.     int t[6] = {5, 10 , 3 , 2, 8, 5};
  51.     int a = sum(t, 6);
  52.     cout << a << endl;
  53.     */
  54.    
  55.    
  56.     //2
  57.    
  58.     /*
  59.     bool t[4] = {1, 1, 1, 0};
  60.     bool a = allTrue(t, 4);
  61.     cout << a << endl;
  62.     */
  63.    
  64.    
  65.     //3
  66.     char[7] = {r ,r ,r ,r ,e ,e ,r};
  67.     char oldChar = 'r';
  68.     char newChar = 'e';
  69.     int r = replace(chrs, 7, oldChar, newChar);
  70.     cout << r << endl;
  71.    
  72.    
  73.    
  74.    
  75.    
  76.    
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement