1 #include<iostream> 2 #include<fstream> 3 using namespace std; 4 class cars{ 5 public: 6 string make; 7 string model; 8 int year; 9 bool transmission; 10 int price; 11 void display() 12 { 13 cout<<"Make "<<make<<endl; 14 cout<<"Model "<<model<<endl; 15 cout<<"year "<<year<<endl; 16 if(transmission) 17 cout<<"transmission "<<"Mannual"<<endl; 18 else 19 cout<<"transmission "<<"Automatic"<<endl; 20 cout<<"price "<<price<<endl; 21 } 22 23 }; 24 int main() 25 { 26 cars arr[3]; 27 ofstream filin; 28 for(int i=0;i<3;i++) 29 { 30 cout<<"Enter the details of car "<< i+1<<endl; 31 cout<<"enter make of car"<<endl; 32 cin>>arr[i].make; 33 cout<<"enter model of car"<<endl; 34 cin>>arr[i].model; 35 cout<<"enter year of car"<<endl; 36 cin>>arr[i].year; 37 cout<<"enter transmission of car"<<endl; 38 cout<<"1. Mannual"<<endl; 39 cout<<"2. Automatic"<<endl; 40 int t; 41 cin>>t; 42 if(t==1)arr[i].transmission=true; 43 else arr[i].transmission=false; 44 cout<<"enter price of car"<<endl; 45 cin>>arr[i].price; 46 } 47 cout<<"1. See car details"<<endl; 48 cout<<"2. Update car details"<<endl; 49 cout<<"3. print all car details"<<endl; 50 cout<<"4. Save cars"<<endl; 51 int q; 52 cin>>q; 53 if(q==1) 54 { 55 cout<<"Enter number of car to search 1 or 2 or 3"<<endl; 56 int model1; 57 cin>>model1; 58 if(model1<3) 59 arr[model1-1].display();// 0 based indexing 60 else 61 cout<<"Wrong number"<<endl; 62 } 63 if(q==2) 64 { 65 cout<<"Enter number of car to update 1 or 2 or 3"<<endl; 66 int model1; 67 cin>>model1; 68 model1--; // 0 based indexing 69 cout<<"enter make of car"<<endl; 70 cin>>arr[model1].make; 71 cout<<"enter model of car"<<endl; 72 cin>>arr[model1].model; 73 cout<<"enter year of car"<<endl; 74 cin>>arr[i].year; 75 cout<<"enter transmission of car"<<endl; 76 cout<<"1. Mannual"<<endl; 77 cout<<"2. Automatic"<<endl; 78 int t; 79 cin>>t; 80 if(t==1)arr[i].transmission=true; 81 else arr[i].transmission=false; 82 cout<<"enter price of car"<<endl; 83 cin>>arr[i].price; 84 } 85 cout<<"1. See car details"<<endl; 86 cout<<"2. Update car details"<<endl; 87 cout<<"3. print all car details"<<endl; 88 cout<<"4. Save cars"<<endl; 89 90 cin>>q; 91 if(q==1) 92 { 93 cout<<"Enter number of car to search 1 or 2 or 3"<<endl; 94 int model1; 95 cin>>model1; 96 if(model1<3) 97 arr[model1-1].display();// 0 based indexing 98 else 99 cout<<"Wrong number"<<endl; 100 } 101 if(q==2) 102 { 103 cout<<"Enter number of car to update 1 or 2 or 3"<<endl; 104 int model1; 105 cin>>model1; 106 model1--; // 0 based indexing 107 cout<<"enter make of car"<<endl; 108 cin>>arr[model1].make; 109 cout<<"enter model of car"<<endl; 110 cin>>arr[model1].model; 111 cout<<"enter year of car"<<endl; 112 cin>>arr[model1].year; 113 cout<<"enter transmission of car"<<endl; 114 cout<<"1. Mannual"<<endl; 115 cout<<"2. Automatic"<<endl; 116 int t; 117 cin>>t; 118 if(t==1)arr[model1].transmission=true; 119 else arr[model1].transmission=false; 120 cout<<"enter price of car"<<endl; 121 cin>>arr[model1].price; 122 } 123 if(q==3) 124 { 125 for(int i=0;i<3;i++) 126 { 127 arr[i].display(); 128 } 129 } 130 else 131 { 132 filin.open("text.txt", ios::app); 133 for(int i=0;i<3;i++) 134 { 135 filin.write((char*)&arr[i], sizeof(arr[i]));// writing into file 136 } 137 filin.close(); 138 } 139 }
identifier "i" is undefined
cin>>arr[i].year; cout<<"enter transmission of car"<<endl; cout<<"1. Mannual"<<endl;
model1
i
arr
arr[i]
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)