Advertisement
vaibhav1906

Class, Structure, Pairs

Nov 17th, 2021
1,518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //Structures, Classes and Pairs
  4.  
  5. struct StudentDetails{
  6.     int age;
  7.     string name;
  8. };
  9.  
  10. class Car{
  11.     public:
  12.         int seater;
  13.         string model;
  14.         int price;
  15. };
  16.  
  17. int main(){
  18.    
  19.     StudentDetails student1; //
  20.    
  21.     student1.age = 14;
  22.     student1.name = "Vaibhav";
  23.    
  24.     StudentDetails student2;
  25.    
  26.     student2 = {16,"Ram"};
  27.    
  28.    
  29.     cout<<"Student 1 name is : "<<student1.name<<endl;
  30.     cout<<"Student 2 name is : "<<student2.name<<endl;
  31.    
  32.     vector<StudentDetails> v;
  33.    
  34. //  for(int i = 0; i<3; i++){
  35. //      StudentDetails temp;
  36. //      int age;
  37. //      string name;
  38. //      cout<<"Age of Student "<< i<<endl;
  39. //     
  40. //      cin>>age;
  41. //      cout<<"Name of Student "<< i<<endl;
  42. //      cin>>name;
  43. //     
  44. //      temp.age = age;
  45. //      temp.name = name;
  46. //      v.push_back(temp);
  47. //  }
  48. // 
  49. //  cout<<"2nd stud age : "<<v[1].age<<endl;
  50.  
  51.     Car c1;
  52.    
  53.     c1.seater = 4;
  54.     c1.model ="Swift";
  55.     c1.price = 700000;
  56.    
  57.     cout<<c1.model<<" have a price of "<<c1.price<<endl;
  58.    
  59.    
  60.     pair<string,int> p;
  61.    
  62.     p.first = "Heloowww";
  63.     p.second = 40; // p ={"hellowwww", 40}
  64.    
  65.     cout<<"first value of pair is : "<<p.first<<endl;
  66.    
  67.     vector<pair<int,string> > vec;
  68.    
  69.     pair<int,string> t;
  70.     t={12,"Apple"};
  71.    
  72.     vec.push_back(t);
  73.     vec.push_back({18,"Sony"});
  74.    
  75.    
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement