# ciso646

***

**1. Character Processing**

```cpp
int main() {
  // Convert a character to uppercase
  char c = 'a';
  c = toupper(c); // c is now 'A'
}
```

**2. Mathematical Operations**

```cpp
int main() {
  // Calculate the absolute value of a number
  int x = -5;
  x = abs(x); // x is now 5
}
```

**3. String Manipulation**

```cpp
int main() {
  // Concatenate two strings
  char s1[] = "Hello";
  char s2[] = "World";
  strcat(s1, s2); // s1 is now "HelloWorld"
}
```

**4. Memory Management**

```cpp
int main() {
  // Allocate memory for a variable
  int* p = (int*)malloc(sizeof(int));
  *p = 5; // Store 5 at memory address pointed by p
}
```

**5. File I/O**

```cpp
int main() {
  // Read a character from a file
  FILE* fp = fopen("file.txt", "r");
  char c = fgetc(fp); // Read the first character from the file
}
```

**6. Date and Time**

```cpp
int main() {
  // Get the current time
  time_t now = time(0);
  struct tm* timeinfo = localtime(&now);
  printf("%d-%d-%d %d:%d:%d\n", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1,
         timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
}
```

**7. Error Handling**

```cpp
int main() {
  // Check if file opening failed
  FILE* fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error opening file");
    return EXIT_FAILURE;
  }

  // Read the first character from the file
  char c = fgetc(fp);
}
```

**8. Networking**

```cpp
int main() {
  // Create a socket
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    perror("Error creating socket");
    return EXIT_FAILURE;
  }

  // Bind the socket to an address
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(80);
  addr.sin_addr.s_addr = INADDR_ANY;
  int bind_result = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
  if (bind_result == -1) {
    perror("Error binding socket");
    return EXIT_FAILURE;
  }

  // Listen for connections
  int listen_result = listen(sock, 5);
  if (listen_result == -1) {
    perror("Error listening on socket");
    return EXIT_FAILURE;
  }
}
```

**9. Multithreading**

```cpp
int main() {
  // Create a thread
  pthread_t tid;
  pthread_create(&tid, NULL, thread_function, (void*)arg);

  // Join the thread
  pthread_join(tid, NULL);
}
```

**10. Synchronization**

```cpp
int main() {
  // Create a mutex
  pthread_mutex_t mutex;
  pthread_mutex_init(&mutex, NULL);

  // Lock the mutex
  pthread_mutex_lock(&mutex);

  // Unlock the mutex
  pthread_mutex_unlock(&mutex);
}
```

**11. Sorting**

```cpp
int main() {
  // Sort an array of integers
  int arr[] = {5, 3, 1, 2, 4};
  qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof(int), compare_function);
}
```

**12. Searching**

```cpp
int main() {
  // Search for a value in an array using binary search
  int arr[] = {1, 2, 3, 4, 5};
  int value = 3;
  int index = binary_search(arr, sizeof(arr) / sizeof(arr[0]), value);
}
```

**13. Hashing**

```cpp
int main() {
  // Create a hash table
  hash_table* ht = create_hash_table(10);

  // Insert a key-value pair into the hash table
  hash_insert(ht, "key", "value");

  // Retrieve a value from the hash table given a key
  char* value = hash_get(ht, "key");
}
```

**14. Recursion**

```cpp
int factorial(int n) {
  if (n == 0) {
    return 1;
  } else {
    return n * factorial(n - 1);
  }
}
```

**15. Dynamic Programming**

```cpp
int main() {
  // Solve the Fibonacci sequence using dynamic programming
  int fib[10];
  fib[0] = 0;
  fib[1] = 1;
  for (int i = 2; i < 10; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
}
```

**16. Graph Algorithms**

```cpp
int main() {
  // Create a graph
  graph* g = create_graph(10);

  // Add an edge to the graph
  add_edge(g, 0, 1, 10);

  // Perform a depth-first search on the graph
  depth_first_search(g, 0);
}
```

**17. Sorting Algorithms**

```cpp
int main() {
  // Sort an array of integers using the bubble sort algorithm
  int arr[] = {5, 3, 1, 2, 4};
  bubble_sort(arr, sizeof(arr) / sizeof(arr[0]));
}
```

**18. Searching Algorithms**

```cpp
int main() {
  // Search for a value in an array using the linear search algorithm
  int arr[] = {5, 3, 1, 2, 4};
  int value = 3;
  int index = linear_search(arr, sizeof(arr) / sizeof(arr[0]), value);
}
```

**19. String Manipulation**

```cpp
int main() {
  // Convert a string to lowercase
  char s[] = "HELLO";
  int length = strlen(s);
  for (int i = 0; i < length; i++) {
    s[i] = tolower(s[i]);
  }
}
```

**20. Memory Management**

```cpp
int main() {
  // Allocate memory for a variable dynamically
  int* p = (int*)malloc(sizeof(int));
  *p = 5; // Initialize the allocated memory

  // Free the allocated memory
  free(p);
}
```

**21. File Input/Output**

```cpp
int main() {
  // Open a file for reading
  FILE* fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error opening file");
    return EXIT_FAILURE;
  }

  // Read the contents of the file
  char ch;
  while ((ch = fgetc(fp)) != EOF) {
    printf("%c", ch);
  }

  // Close the file
  fclose(fp);
}
```

**22. Command-Line Arguments**

```cpp
int main(int argc, char* argv[]) {
  // Check if the command-line argument is present
  if (argc > 1) {
    printf("The command-line argument is: %s\n", argv[1]);
  } else {
    printf("No command-line argument provided\n");
  }
}
```

**23. Mathematical Functions**

```cpp
int main() {
  // Calculate the sine of an angle
  double angle = 30;
  double sine = sin(angle * M_PI / 180);
}
```

**24. Random Numbers**

```cpp
int main() {
  // Generate a random number between 0 and 9
  srand(time(NULL));
  int random_number = rand() % 10;
}
```

**25. Date and Time Manipulation**

```cpp
int main() {
  // Get the current date and time
  time_t now = time(NULL);
  struct tm* timeinfo = localtime(&now);
  printf("%d/%d/%d %d:%d:%d\n", timeinfo->tm_mday, timeinfo->tm_mon + 1, timeinfo->tm_year + 1900, timeinfo->tm_hour,
         timeinfo->tm_min, timeinfo->tm_sec);
}
```

**26. Input/Output Redirection**

```cpp
int main() {
  // Redirect standard output to a file
  freopen("output.txt", "w", stdout);
  printf("This output will be written to the file output.txt\n");
}
```

**27. Error Handling**

```cpp
int main() {
  // Handle an error using the try-catch block
  try {
    // Code that may throw an exception
  } catch (const std::exception& e) {
    std::cerr << "An exception occurred: " << e.what() << "\n";
  }
}
```

**28. Object-Oriented Programming**

```cpp
class MyClass {
public:
  int x;
  MyClass(int x) : x(x) {}
  int get_x() { return x; }
};

int main() {
  // Create an object of the MyClass class
  MyClass my_object(5);
  std::cout << my_object.get_x() << "\n";
}
```

**29. Inheritance**

```cpp
class BaseClass {
public:
  int x;
  BaseClass(int x) : x(x) {}
};

class DerivedClass : public BaseClass {
public:
  int y;
  DerivedClass(int x, int y) : BaseClass(x), y(y) {}
  int get_y() { return y; }
};

int main() {
  // Create an object of the DerivedClass class
  DerivedClass derived_object(5, 10);
  std::cout << derived_object.get_x() << " " << derived_object.get_y() << "\n";
}
```

**30. Polymorphism**

```cpp
class Shape {
public:
  virtual double get_area() = 0;
};

class Circle : public Shape {
public:
  double radius;
  Circle(double radius) : radius(radius) {}
  double get_area() { return M_PI * radius * radius; }
};

class Rectangle : public Shape {
public:
  double length;
  double width;
  Rectangle(double length, double width) : length(length), width(width) {}
  double get_area() { return length * width; }
};

int main() {
  // Create an array of shapes
  Shape* shapes[] = {new Circle(5), new Rectangle(10, 5)};

  // Calculate the area of each shape
  for (int i = 0; i < 2; i++) {
    std::cout << shapes[i]->get_area() << "\n";
  }
}
```

**31. Templates**

```cpp
template <typename T>
T max(T a, T b) { return (a > b) ? a : b; }

int main() {
  int i = max(5, 10);
  double d = max(3.5, 10.5);
  std::cout << i << " " << d << "\n";
}
```

**32. Exception Handling**

```cpp
int main() {
  try {
    // Code that may throw an exception
    throw std::runtime_error("An error occurred");
  } catch (const std::exception& e) {
    std::cerr << "Error: " << e.what() << "\n";
  }
}
```

**33. Iterators**

```cpp
std::vector<int> numbers = {1, 2, 3, 4, 5};

// Iterate over the vector using an iterator
for (std::vector<int>::iterator it = numbers.begin(); it != numbers.end(); ++it) {
  std::cout << *it << " ";
}
```

**34. Containers**

```cpp
std::map<std::string, int> my_map = {{"key1", 1}, {"key2", 2}, {"key3", 3}};

// Access the value associated with a key
int value = my_map["key2"];
std::cout << value << "\n";
```

**35. Algorithms**

```cpp
std::vector<int> numbers = {1, 2, 3, 4, 5};

// Sort the vector in ascending order
std::sort(numbers.begin(), numbers.end());
for (int number : numbers) {
  std::cout << number << " ";
}
```

**36. Input/Output Streams**

```cpp
std::ofstream output_file("output.txt");
output_file << "This is a line of text that will be written to the file\n";
output_file.close();
```

**37. Regular Expressions**

```cpp
std::regex phone_number_regex("^(\\d{3}-){2}\\d{4}$");

// Check if a string matches a phone number pattern
bool is_phone_number = std::regex_match("123-456-7890", phone_number_regex);
```

**38. Multithreading**

```cpp
#include <thread>

void thread_function() {
  std::cout << "This is running in a separate thread\n";
}

int main() {
  std::thread t(thread_function);
  t.join();
}
```

**39. Networking**

```cpp
#include <sys/socket.h>
#include <netinet/in.h>

int main() {
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd == -1) {
    perror("Error creating socket");
    return EXIT_FAILURE;
  }

  // ...
}
```

**40. Database Connectivity**

```cpp
#include <mysql.h>

int main() {
  MYSQL* conn = mysql_init(NULL);
  if (conn == NULL) {
    fprintf(stderr, "Error initializing MySQL connection\n");
    return EXIT_FAILURE;
  }

  // ...
}
```

**41. XML Parsing**

```cpp
#include <rapidxml.hpp>

int main() {
  rapidxml::xml_document<> doc;
  doc.parse<0>(xml_string);

  // ...
}
```

**42. JSON Parsing**

```cpp
#include <jsoncpp/json.h>

int main() {
  Json::Value root;
  std::ifstream ifs("json_file.json");
  ifs >> root;

  // ...
}
```

**43. Web Scraping**

```cpp
#include <curl/curl.h>
#include <iostream>

int main() {
  CURL* curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  curl_easy_perform(curl);

  // ...
}
```

**44. Data Visualization**

```cpp
#include <matplotlibcpp.h>

int main() {
  std::vector<double> x = {1, 2, 3, 4, 5};
  std::vector<double> y = {2, 4, 6, 8, 10};

  matplotlibcpp::plot(x, y);
  matplotlibcpp::show();
}
```

**45. Machine Learning**

```cpp
#include <mlpack/core.hpp>

int main() {
  arma::mat data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
  arma::rowvec labels = {0, 1, 0};

  // ...
}
```

**46. Image Processing**

```cpp
#include <opencv2/opencv.hpp>

int main() {
  cv::Mat image = cv::imread("image.jpg");
  cv::imshow("Image", image);
  cv::waitKey(0);

  // ...
}
```

**47. Signal Processing**

```cpp
#include <fftw3.h>

int main() {
  double data[] = {1, 2, 3, 4, 5, 6, 7, 8};
  fftw_complex out[8];

  // ...
}
```

**48. Natural Language Processing**

```cpp
#include <nltk/corpus.hh>
#include <nltk/tokenizer.hh>

int main() {
  nltk::corpus::load("words.txt");
  nltk::PunktSentenceTokenizer tokenizer;

  std::string text = "This is a sentence. This is another sentence.";
  std::vector<std::string> sentences = tokenizer.sentences(text);

  // ...
}
```

**49. Computer Graphics**

```cpp
#include <GLFW/glfw3.h>

int main() {
  glfwInit();
  GLFWwindow* window = glfwCreateWindow(640, 480, "Window", NULL, NULL);

  // ...
}
```

**50. Game Development**

```cpp
#include <SDL.h>

int main() {
  SDL_Init(SDL_INIT_EVERYTHING);
  SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480,
                                         SDL_WINDOW_OPENGL);

  // ...
}
```
