GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-May-2006, 05:43
panagiotis13 panagiotis13 is offline
New Member
 
Join Date: May 2006
Posts: 3
panagiotis13 is on a distinguished road

I need help on C++ Uni Project


I have to work on a project and i cannot find a way to solve this:

Develop a MS DOS command prompt emulator, that has the following DOS commands:
CLS
VER
DIR
CD
DOSKEY
HELP
EXIT

Any ideas?
Thank you
  #2  
Old 01-May-2006, 07:32
cjavac#c++_vbP cjavac#c++_vbP is offline
Junior Member
 
Join Date: Mar 2006
Location: Miami, FL
Posts: 42
cjavac#c++_vbP is on a distinguished road

Re: I need help on C++ Uni Project


system('command prompt command');

read up or research on this system function for more information.
  #3  
Old 01-May-2006, 07:46
panagiotis13 panagiotis13 is offline
New Member
 
Join Date: May 2006
Posts: 3
panagiotis13 is on a distinguished road

Re: I need help on C++ Uni Project


thank u!

if i understand what u said before, i can use dos commands, using system("command"), is that right?

it seems to work with
system("CLS")

if you like take a look at my code:
CPP / C++ / C Code:
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>

using namespace std;

int main()
{
  string x;
   getline (cin,x);

do{
   if (x=="help")
   {
  string line;
  ifstream myfile ("help.txt"); //Reads the text from a help file
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }
  break;
  
}
   if (x=="cls") //The CLS command, it seems to work fine...
   {      system("CLS");
      break;
   }
   if (x=="ver") //This is the VER command, it displays the version of my program!
   {
                 cout << "Pan O.S. Version 1.0 April 2006 ALL RIGHTS RESERVED\n";
                 }
   break;
}
while (x!="exit"); //done with EXIT command

  cin.get();
  return 0;
}


I still need help for the following:
- The commands DIR, DOSKEY and CD
- How can I make my program work for more than one command each time? When i run it, i can only type one command. When i type a second one, the program closes.

THANK YOU!
Last edited by LuciWiz : 02-May-2006 at 07:24. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #4  
Old 01-May-2006, 08:05
cjavac#c++_vbP cjavac#c++_vbP is offline
Junior Member
 
Join Date: Mar 2006
Location: Miami, FL
Posts: 42
cjavac#c++_vbP is on a distinguished road

Re: I need help on C++ Uni Project


whether or not the command is a valid or invalid one. system('command'); will automatically handle that if it does not recognize the command.

Remember it is emulating/imitating the command prompt, so it will spit out whatever a regular command prompt does.

System will handle these calls without you checking the input strings passed in.
Example
system("DIR");
system("nonsense");
  #5  
Old 01-May-2006, 08:06
cjavac#c++_vbP cjavac#c++_vbP is offline
Junior Member
 
Join Date: Mar 2006
Location: Miami, FL
Posts: 42
cjavac#c++_vbP is on a distinguished road

Re: I need help on C++ Uni Project


Also stuff what you have in main into a function, and you can either use a loop to call the function more than one times or recursion.
  #6  
Old 02-May-2006, 00:09
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: I need help on C++ Uni Project


I am quite sure that calling DOS commands from your program to emulate DOS is not going to get you a good grade. I'll bet the requirement is to "write the code that processes the command" so you need to write the steps to accomplish the task, not simply call DOS.

Make each command a function. This will keep your code easier to read and debug.
__________________

Age is unimportant -- except in cheese
  #7  
Old 02-May-2006, 09:10
panagiotis13 panagiotis13 is offline
New Member
 
Join Date: May 2006
Posts: 3
panagiotis13 is on a distinguished road

Re: I need help on C++ Uni Project


Quote:
Originally Posted by WaltP
I am quite sure that calling DOS commands from your program to emulate DOS is not going to get you a good grade. I'll bet the requirement is to "write the code that processes the command" so you need to write the steps to accomplish the task, not simply call DOS.

Make each command a function. This will keep your code easier to read and debug.

That is true...
So any ideas for CLS Command?

I have tried to clear the screen like this:
Code:
if (x=="cls") { cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; cout << "\n"; }

But it doesnt seem to work...

- I think VER, HELP and EXIT commands are OK.
- DOSKEY: I think i will try to create a LOG file or something
- DIR: I found something, it looks easy www.informit.com
- CD: I have no idea...

ANY HELP???
Thank you
  #8  
Old 02-May-2006, 14:31
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: I need help on C++ Uni Project


CLS: don't know why that doesn't work, perhaps it doesn't flush the buffer. try using endl instead of "\n". On specific operating systems there are several options for clearing the screen, detailed here: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
CD: you could keep an internal variable of the current directory, or if on Windows you can use the Get/SetCurrentDirectory functions.
  #9  
Old 02-May-2006, 17:12
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: I need help on C++ Uni Project


Quote:
Originally Posted by panagiotis13
I have tried to clear the screen like this:
...

But it doesnt seem to work...
Guidelines 1 & 2
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Simple 1D Array coding project rho C++ Forum 2 27-Jun-2005 19:05
c programming : project idea ??? batrsau C++ Forum 2 09-Jun-2005 04:55
project in c pointer C Programming Language 1 26-Apr-2005 15:46
Community Project Proposal dsmith Miscellaneous Programming Forum 71 19-Feb-2005 12:26
Help with project. anignna C Programming Language 12 27-Apr-2004 07:51

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.