Advertisement
bogdanNiculeasa

Struct examples

Jan 12th, 2021
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. struct Address {
  6.     char city[50];
  7.     char street[50];
  8.     int number;
  9.     int apartmentNumber;
  10.     int floorNumber;
  11. };
  12.  
  13. struct Student {
  14.     int age;
  15.     int mathMean;
  16.     int number;
  17.     Address workAddress;
  18.     Address homeAddress;
  19. };
  20.  
  21. struct Car {
  22.     char color[20];
  23.     int numberOfDoors;
  24.     int numberOfWindows;
  25.     int cylindricCapacity;
  26.     char brand[30];
  27.     char model[30];
  28. };
  29.  
  30. int main() {
  31.     struct Car myCar;
  32.     int numbers[20];
  33.  
  34.     struct Car cars[3];
  35.  
  36.     for(int i = 0; i < 2; i++) {
  37.         cout << "Enter car brand: ";
  38.         char brand[15], model[15], color[20];
  39.         cin >> brand;
  40.         strcpy(cars[i].brand, brand);
  41.  
  42.         cout << "\nEnter car model: ";
  43.         cin >> model;
  44.         strcpy(cars[i].model, model);
  45.  
  46.         cout << "\nEnter color: ";
  47.         cin >> color;
  48.         strcpy(cars[i].color, color);
  49.  
  50.         cout << "\nEnter number of doors: ";
  51.         cin >> cars[i].numberOfDoors;
  52.  
  53.         cout << "\nEnter number of windows: ";
  54.         cin >> cars[i].numberOfWindows;
  55.  
  56.         cout << "\nEnter cc: ";
  57.         cin >> cars[i].cylindricCapacity;
  58.     }
  59.  
  60.  
  61.     cout << "Available cars: \n\n";
  62.     cout << "Brand\tModel\tColor\t#Doors\t#Windows\tCC\n";
  63.     for(int i = 0; i < 2;i++) {
  64.         cout <<cars[i].brand <<"\t" << cars[i].model << "\t" << cars[i].color << "\t" << cars[i].numberOfDoors << "\t" << cars[i].numberOfWindows << "\t" << cars[i].cylindricCapacity;
  65.         cout << endl;
  66.     }
  67.  
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement