Write a program that creates computer model by using Classes, Program should be able to add, delete, modify and View the Record by using member functions.
Make sure following qualities should be implemented.
· Manufacture
· Type
· Capacity
#include <iostream>
#include <string>
using namespace std;
class Record{
private:
string manufacture;
string type;
float capacity;
public:
Record(){}
Record(string manufacture,string type,float capacity){
this->manufacture = manufacture;
this->type = type;
this->capacity = capacity;
}
void add(){
cout<<"Enter a manufacture: ";
getline(cin,this->manufacture);
cout<<"Enter a type: ";
getline(cin,this->type);
cout<<"Enter a capacity: ";
cin>>this->capacity;
}
void viewRecord (){
cout<<"Manufacture: "<<manufacture<<"\n";
cout<<"Type: "<<type<<"\n";
cout<<"Capacity: "<<capacity<<"\n\n";
}
void modify(){
cout<<"Enter a new manufacture: ";
getline(cin,this->manufacture);
cout<<"Enter a new type: ";
getline(cin,this->type);
cout<<"Enter a new capacity: ";
cin>>this->capacity;
}
~Record(){}
};
int main(){
Record records[100];
int totalRecords=0;
int ch=-1;
while(ch!=5){
//add, delete, modify and View the Record
cout<<"1. Add record.\n";
cout<<"2. Delete record.\n";
cout<<"3. Modify record.\n";
cout<<"4. View records.\n";
cout<<"5. Exit.\n";
cout<<"> ";
cin>>ch;
cin.ignore();
if(ch==1){
records[totalRecords].add();
totalRecords++;
}else if(ch==2){
if(totalRecords>0){
for(int i=0;i<totalRecords;i++){
cout<<"ID: "<<(i+1)<<"\n";
records[i].viewRecord();
}
cout<<"Select id to delete: ";
int id;
cin>>id;
id--;
if(id<0 || id>=totalRecords){
cout<<"\nSelect a correct id.\n\n";
}else{
for(int i=id;i<totalRecords-1;i++){
records[i]=records[i+1];
}
totalRecords--;
cout<<"\nThe record has been deleted.\n\n";
}
}else{
cout<<"\nThe list is empty.\n\n";
}
}else if(ch==3){
if(totalRecords>0){
for(int i=0;i<totalRecords;i++){
cout<<"ID: "<<(i+1)<<"\n";
records[i].viewRecord();
}
cout<<"Select id to edit: ";
int id;
cin>>id;
id--;
if(id<0 || id>=totalRecords){
cout<<"\nSelect a correct id.\n\n";
}else{
cin.ignore();
records[id].modify();
cout<<"\nThe record has been updated.\n\n";
}
}else{
cout<<"\nThe list is empty.\n\n";
}
}else if(ch==4){
if(totalRecords>0){
for(int i=0;i<totalRecords;i++){
cout<<"ID: "<<(i+1)<<"\n";
records[i].viewRecord();
}
}else{
cout<<"\nThe list is empty.\n\n";
}
}else if(ch==5){
//exit
}else{
cout<<"\nWrong menu item.\n\n";
}
}
system("pause");
return 0;
}
Comments
Leave a comment