Advertisement
KingAesthetic

Example 3 for C++

May 20th, 2024
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Create a structure , assign values , and print the members:
  7.  
  8.     struct {
  9.         int myAge;
  10.         string myDepartment;
  11.         string FavoriteServer;
  12.  
  13.     } myStructure;
  14.  
  15. // Assign values to members:
  16.     myStructure.myAge = 17;
  17.     myStructure.myDepartment = "Software Engineering";
  18.     myStructure.FavoriteServer = "Hidden Devs";
  19.  
  20. // Print the members:
  21.     cout << myStructure.myAge << "\n";
  22.     cout << myStructure.myDepartment << "\n";
  23.     cout << myStructure.FavoriteServer << "\n";
  24.  
  25. // Reference to cars:
  26.     string cars = "Bugatti";
  27.     string &vehicle = cars;
  28.     string *ptr = &vehicle;
  29.     cout << cars << "\n";
  30.     cout << &vehicle << "\n";
  31.     cout << ptr << "\n";
  32.  
  33. // To multiply two numbers:
  34.     int a, b;
  35.     int product;
  36.     cout << "Type a number: " << "\n";
  37.     cin >> a;
  38.     cout << "Type another number: " << "\n";
  39.     cin >> b;
  40.     product = a * b;
  41.     cout << product;
  42. // Create an array of professions and Loop through it:
  43. string professions[2][4] {
  44.         {"Teaching", "Engineering", "Medicine", "Law"},
  45.         {"Business", "Accounting", "Politician", "electricians"}
  46. };
  47. for (int k = 0; k < 2; k++) {
  48.     for (int l = 0; l < 4; l++) {
  49.         cout << professions[k][l] << "\n";
  50.     }
  51. }
  52.  
  53. // Switch to print my profession : Engineering:
  54. int (profession);
  55. switch (7) {
  56.     case 1:
  57.         cout << "Medicine";
  58.         break;
  59.     case 2:
  60.         cout << "Law";
  61.         break;
  62.     case 3:
  63.         cout << "Business";
  64.         break;
  65.     case 4:
  66.         cout << "Accounting";
  67.         break;
  68.     case 5:
  69.         cout << "Political Science";
  70.         break;
  71.     case 6:
  72.         cout << "Psychology";
  73.         break;
  74.     case 7:
  75.         cout << "Engineering";
  76.         break;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement