Thread: I need help on C++ Uni Project

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    7

    I need help on C++ Uni Project

    I have a uni project and i need some help!

    i have to develop an MS-DOS command prompt emulations, that has the following dos commands:

    CLS
    VER
    DIR
    CD
    DOSKEY
    HELP
    EXIT

    ANY IDEAS??
    thank u

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by panagiotis13
    ANY IDEAS??
    Yeah, start working. Then post some code when you're having trouble.
    Sent from my iPadŽ

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Because wandering from board to board has been so productive so far.
    http://forums.devshed.com/c-programm...ed-347717.html

    How about actually showing what you've managed to achieve so far. You're at university now, not pre-school, show some initiative for goodness sake.

    I mean, being able to read in a command and print it back out as say "you typed CD" would at least show that you've made some effort and have a grasp of the basics.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    7
    i really don know how to start...

    any tips??

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Open your compiler, then create a new source file...
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    couldnt you use the system("dos command") using a switch statement in dev-c
    just a thought, am doing A level computing so im not an expert.

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    They want him to emulate the commands, not call them.

    And besides, I'd imagine this is being done on Sun OS or something similar that doesn't have those particular commands (atleast by that name).
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    7
    QUESTION:

    create one program for each commad? let's say, CD.EXE, DOSKEY.EXE etc?

    or create a single program, that reads the input from the user and calls the right fuction for each command, using IF (If input=CLS then ... )

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > i really don know how to start...
    How about starting with the "EXIT" command?
    That ought to be easy enough.

    Or carefully study your previous programming assignments for clues. These things tend to build on knowledge acquired in previous classes and assignments.
    Unless of course you got someone else to do those as well, in which case you're just in free fall
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    7
    ok done something... check out my code:

    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;
    }
    So far, HELP, CLS, VER and EXIT commands seem to work.
    I really need some help on CD and DIR commands. And i have an other problem:

    How can i keep the command window open for more than one command? When my program runs, it works only for the first command. It exits when i type the next command.

    Thank you

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    See - that wasn't too bad, now we're getting somewhere.

    > How can i keep the command window open for more than one command?
    This should be inside your while loop, otherwise you can only enter one command.
    > getline (cin,x);

    > I really need some help on CD and DIR commands
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608
    The chdir() call is basically your CD command, and a loop calling findfirst / findnext is your DIR command.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    7
    Quote Originally Posted by Salem
    The chdir() call is basically your CD command, and a loop calling findfirst / findnext is your DIR command.
    Can you explain me this a little more please? I really need some help!

    Thank you

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    chdir() changes your working directory (and getcwd() tells you your current working directory). Those two functions will take care of your CD command.

    You can use opendir(), readdir(), and closedir() to emulate the DIR command. (Or findfirst etc.)

    If you don't know anything about a function, use man or google:
    Code:
    $ man readdir
    Code:
    google for "readdir"
    As for DOSKEY . . . I guess that means you can enter something like "command 1" and it will repeat command 1. You'll need to store the previous commands. Try a vector.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Can you explain me this a little more please?
    Well something like
    Code:
    if ( x == "cd" ) {
      string whereToCdTo;
      cin >> whereToCdTo;
      chdir( whereToCdTo.c_str() );
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Registered User
    Join Date
    May 2006
    Posts
    7
    Quote Originally Posted by dwks
    As for DOSKEY . . . I guess that means you can enter something like "command 1" and it will repeat command 1. You'll need to store the previous commands. Try a vector.
    Ok vector it is! so i try this:

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <fstream>
    #include <string>
    #include <windows.h> 
    #include <dir.h>
    #include <vector>
    
    using namespace std;
    using std::string;
    
    int main()
    {
     string x;
     std:: vector <std::string> doskey_vector;
    do{   
        
        cout << "OS>";
        getline (cin,x);  
        int j;
        for (j = 0; j < 20; j++)
        doskey_vector.at(j) = x;
    ...
    ...
    What I did wrong? My program runs, but when i type something, the command window closes.

    I want to store let's say, the last 10 commands that the user types, and then use DOSKEY to view them. Any help??


    Thank u

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. Simple Bank Account Uni Project Help!!!
    By griff in forum C Programming
    Replies: 3
    Last Post: 05-09-2003, 05:49 PM