Your program should also have history feature. That is, your program should store at most last then commands. A user should be able to view these commands by typing !. A command from the history can be executed by type !n (where n is the command number in the history that the user wants to execute). Note that the history feature could be used any time, even after logging out and then logging in to your account. That means, the history should be stored permanently. Also, note that you should not have more than 10 previous commands in the history.
the code which i tried is:
#include<iostream>
using namespace std;
int main()
{
int x=0;
string history[10];
string command[20]={"ls","pwd","cat","cal","exit","cd","mkdir","rmdir","clear","date"}
string cm,fname,name;
int cm_no=-1;
cout<<"Enter your command : "<<endl;
cin>>cm;
if(strlen(cm)<=80)
{
for(i=0,i<10,i++)
{
if(cm==command[i])
cm_no=i;
history[x]=cm;
++x;
}
if(cm_no==-1)
cout<<"MyShell%Not a valid command"<<endl;
}
esle
{
cout<<"MyShell%Not a valid command"<<endl;
}
switch(cm){
case (1): // LS
cout<<endl;
system("ls");
break;
case(2): //pwd
cout<<endl;
system("pwd");
cout<<endl;
break;
case(3): //cat
cout<<"Enter file name:"<<endl;
cin>>fname;
system("cat fname");
break;
case(4): //cal
cout<<endl;
system("cal");
cout<<endl;
break;
case(5): //exit
system("exit");
break;
case(6): //cd
system("cd");
break;
case(7): //mkdir
cout<<"Enter a name: "<<endl;
cin>>name;
system("mkdir name");
break;
case(8): //rmdir
cout<<"Enter a name: "<<endl;
cin>>name;
system("rmdir name");
break;
case(9): //clear
system("clear");
break;
case(10): //date
cout<<end;
system("date");
break;
}
return 0;
}
i need your advice ... aslo its need file for the history but i don't remember how to use it ..
plz help

New Topic/Question
This topic is locked




MultiQuote


|