Community discussion forum

Can any one help me Learn

  • 2 years ago

    hi everyone

    i'v just started to learn visual studio,and riht now i'm struggling to finish my assignment if possible someone help me finish my work.

    program required

    Assessment:

     

    Write a program that tests the user in their knowledge of the timetable up to ten times (i.e. the largest number you will have to deal with is 100 - 10 × 10 - which is worth knowing if you are attempting the extension work for the extra five marks).

     

    Start the program by asking for the user's name (this can just be one word, e.g. Steve).

     

    Check that the name is in the class list and retrieve the computing id for that user. Tell the user you are starting the test, for example:

     

    Please enter your name: Steve

    Student id: 1000007 starting the test.

     

    If their name is not in the class list then output:

     

    Please enter your name: Charles

    Charles, you are not required to take this test.

     

    End of program

    Press any key to continue . . .

     

    The program should then enter a do … while testing loop where it:

    1. Randomly generates two integer values

     

    2. Prompts with the product, e.g.

    Steve, what is 10 x 8?

     

    3. Reads the user's answer

     

    4. If correct it responds with:

    Well done, Steve, you are correct.

    And counts this as a correct answer

     

    5. If incorrect it responds with:

    That's not right, Steve, the correct answer is 80

    And counts this as an incorrect answer.

     

    6. The user is then asked:

    Do you want to continue (y/n):

     

    7. The testing loop continues is the answer is y or Y.

     

     

    8. The program outputs:

    Correct answers: 1

    Incorrect answers: 1

     

    End of program

     

    Write functions having the following prototypes in your program:

    bool isValidName( string pName );

    This passes a character string containing the possible name and checks that it is valid.

    string convertName ( string pName );

    This passes the character string containing the name and returns the student's computer id.

     

     

    An example output is as follows:

     

    Please enter your name: Steve

    Student id: n0000001 starting the test.

    Steve what is nine times one? Nine

    Well done, Steve, you are correct.

    Do you want to continue (y/n): y

    Steve what is four times three? Twelve

    Well done, Steve, you are correct.

    Do you want to continue (y/n): y

    Steve what is ten times five? Fifty

    Well done, Steve, you are correct.

    Do you want to continue (y/n): y

    Steve what is two times eight? Sixteen

    Well done, Steve, you are correct.

    Do you want to continue (y/n): y

    Steve what is eight times nine? Seventy two

    Well done, Steve, you are correct.

    Do you want to continue (y/n): y

    Steve what is two times one? Five

    That is not right, Steve, the correct answer is two.

    Do you want to continue (y/n): n

    Correct answers: 5

    Incorrect answers: 1

    End of program

    Press any key to continue . . .

     

     

     

  • 2 years ago

    Hello,

    I'm writing some code for your assignment, but there is a questions so far :

    • What's the operation of function 'isValidName'? (what dose it do ?)... because if it checks that the student (its name) exists in the 'class list', then it will be used in function 'convertName'... in this way, it's not only excess and vain but will decrease the performance and increase the repetitive codes.In fact the code can be in function 'convertName', instead of being in another function ('isValidName').
  • 2 years ago

    Please, do not do homework/assignments for people.

    The only way you can learn is to have guided 'nudges' from the community instead of having it all done for you.

    Not to mention the fact that it is outright plaigarism and cheating.

  • 2 years ago

    Hi,

    I've written a complete program for your request.

    Program  : Lettered_Numbers.cpp
    Language : C++
    Compiler : VC++6 - Win32 Console App

    I Also wrote a separate utility, that manipulates the 'Class_List' file...
    Before using the 'Lettered_Numbers' program, you should add some               
    students to the 'Class_List' file, with 'Class_List_Manipulation' program,
    and then copy 'Class_List' file to the Lettered_Numbers's program folder.

    I didn't find a good way to upload files, but if anyone know a good one tell me then!

    **************************************************

    Program : [Lettered_Numbers.cpp]

    // Begin of File

    //************************************************
    // Programmer : Mohammad Rastkar
    // Last Build : 5_5_07
    // Compiler   : VC++6 - Win32 Console App
    // Purpose    : Asks some questions in multiplication (answer is in range of 1~100)
    //************************************************


    //////////////<  Includes  >/////////////////

    #include <iostream>
    using namespace std;

    #include <fstream> // file interactions
    #include <string> // class string
    #include <cstdlib> // system(), exit(), rand(), srand()
    #include <time.h> // time()
    #include <conio.h>  // getch()


    //////////////<  Declarations  >/////////////

    string convertName  ( string ); // return ID of a student in class list or return "ERR" -> error Or "NF" -> not found
    string numberToWord ( int );    // converting a number from 1 to 100 to its corresponding word

    //////////////////<  main  >/////////////////

    int main()
    {
     string std_name,
         std_id,
         res,
         temp;

     int    num1,
         num2,
         correct   =0,
         incorrect =0;
     
     char   loop;
     
     system("cls"); // clear screen
     
     cout << "Please enter your name : ";
     cin  >> std_name;

     std_id = convertName( std_name );

     if (std_id == "ERR")
     {
      cout << "\n\n Can't open or create 'Class_List' file" << endl;
      system ( "pause" );
      return 1;
     }

     if ( std_id ==  "NF")
     {
      cout << std_name << ", you are not required to take this test. \n\nEnd of program" << endl;
      system ("pause");
      
      return 0;
     }

     cout << "\nStudent id : " << std_id << ", starting the test.\n-> Please answer with lowercase letters. [100 = hundred]\n";
     srand( (unsigned)time( NULL ) ); // seed the random_number_generator with the current time
     
     do
     {
      num1 = rand()%10 + 1; // a random number : 1~10
      num2 = rand()%10 + 1;

      cout << '\n' << std_name <<  ", what is " << numberToWord(num1) << " times " << numberToWord (num2) << " ? ";
      cin  >> res;

      if (cin.get() != 10) // if there is not one word... (ASCII of [Enter] == 10)
      {
       cin >> temp;
       res += ' ' + temp;
      }
      
      if ( res == numberToWord(num1 * num2) )
      {
       cout << "Well done, " << std_name << ", you are correct.\n";
       correct++;
      }
      else
      {
       cout << "That is not right, " << std_name << ", the correct answer is : " << numberToWord(num1 * num2) << ".\n";
       incorrect++;
      }

      
      cout << "Do you want to continue (y/n) : ";
      loop = getch();

     }while (loop == 'y' || loop == 'Y' );

     cout << "\nCorrect answers : " << correct << "\nIncorrect answers : " << incorrect;
     cout << "\nEnd of program" << endl;
     system ("pause");
     return 0;
    }


    ///////////////<  Definitions  >/////////////

    string convertName ( string pName )
    {
     fstream *fs = new fstream( "Class_List.txt", ios::in);
     string file_str;
     
     if (!fs)
      return string("ERR"); // ERRor
     
     (*fs) >> file_str; // store whole of the file in 'file_str'

     fs->close();
     delete fs;
     fs=0;

     int pos = file_str.find(pName); // first character of Name

     if (pos == string::npos)
      return string("NF"); // Not Found

     pos -= 2; // last of ID

     int del_num = pos - file_str.rfind('>', pos); // ID length

     pos = file_str.rfind('>', pos) + 1; // first of ID

     return ( file_str.substr (pos, del_num) ); // ID
    }

    string numberToWord ( int num )
    {
     string zero_to_nine       [11] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        string ten_to_nineteen    [10] = { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
     string twenty_to_ninety   [10] = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

     if (num == 100)
      return string("hundred");
     
     if ( int(num/10) == 1) // 10~19
      return ten_to_nineteen[num%10];

     if ( int(num/10) == 0 )
      return zero_to_nine[num%10];
     
     if ( num%10 == 0 )
      return twenty_to_ninety[num/10];

     return ( twenty_to_ninety[num/10] + ' ' + zero_to_nine[num%10] );
    }

    // End of File

     

    **************************************************

    Utility : [Class_List_Manipulation.cpp]

    // Begin of File

    //************************************************
    // Programmer : Mohammad Rastkar
    // Last Build : 5_1_07
    // Compiler   : VC++6 - Win32 Console App
    // Purpose    : Separate utility to manipulate a 'Class_List' file (add, delete, modify, list Records)
    //    for using later, with 'Lettered_Numbers' program
    //************************************************

    /////////////< Includes    >/////////////

    #include <stdlib.h> // system()
    #include <conio.h> // getch()
    #include <fstream>
    #include <string>

    #include <iostream>
    using namespace std;

    //////////////<  Variables   >//////////////

    char    choice; // for choosing from menu
    fstream *fs; // file stream for 'Class_List' file
    string  file_str; // string as 'Class_List' file


    /////////////< Main    >/////////////

    int main()
    {
     fs = new fstream( "Class_List.txt", ios::in);
     
     if (!fs)
     {
      cout << "\n Can't open or create 'Class_List' file" << endl;
      system ( "pause" );
      return 1;
     }
     
     (*fs) >> file_str; // store whole of the file in 'file_str'

     fs->close();
     delete fs;
     fs=0;
     
     while (1)
     {
      do  // menu
      {
       system( "cls" ); // clear screen
        
       cout << "\n    < Class List > \n\n";
       cout << "(1) Add     a new student \n";
       cout << "(2) Modify  an existing student's information\n";
       cout << "(3) Delete  an existing student \n";
       cout << "(4) Display students' informations \n";
       cout << "(5) Exit \n\n";
       cout << " Enter a choice (1-5) : " << flush;
       choice = getch();

      } while ( choice < '1' || choice > '5');

      system( "cls" );

      switch ( choice )
      {
       int del_num; // number of characters for deletion
       int pos;  // a position in the string
       int  rows; // on Displaying, for each 25 rows in the screen there is a pause

      
      case '1' : // Add Student
       {

        string input; // ID of student
        cout << "\n\t\t < Entering a new student > ";
        cout << "\n   Enter the following informations for the new student : ";
        
        cout << "\n\n ID : ";
        cin  >> input;

        file_str += input + '>'; // '>' -> delimiting students' informations

        cout << "\n Name (Only one word) : "; // can be more than one word
        cin  >> input;
        
        file_str += input + '>';

        cout << "\n Student was added." << endl;
        system ( "pause" );
        
        break;
       }

      case '2' : // Modify Student
       {

        string input;
        cout << "\n Enter Student ID, that you want modify its informatin : ";
        cin  >> input;

        pos = file_str.find(input);

        if (pos == string::npos)
        {
         cout << "\n Your specified student doesn't exist in the list" << endl;
         system ( "pause" );
         break;
        }

        cout << "\nEnter new informations for this student : ";

        cout << "\n\n ID : ";
        cin  >> input;

        del_num = file_str.find('>', pos+1)-pos; // ID : first character of ID to first '>'
        
        file_str.replace (pos, del_num, input); // replace the current ID with the new one

        
        cout << "\n Name (Only one word) : ";
        cin  >> input;
        
        pos = file_str.find('>', pos+1) + 1; // first character of Name
        del_num = file_str.find('>', pos+1)-pos; // Name : first character after first '>' to second '>'

        file_str.replace (pos, del_num, input); // replace the current Name with the new one

        cout << "\n Record was modified." << endl;
        system ( "pause" );

        break;
       }


      case '3' : // Delete Record
       {
        string input;
        cout << "\n Enter student ID, for deletion : ";
        cin  >> input;

        pos = file_str.find(input);

        if (pos == string::npos)
        {
         cout << "\n Your specified student doesn't exist in the list" << endl;
         system ( "pause" );
         break;
        }

        file_str.erase ( file_str.begin()+pos, file_str.begin()+file_str.find('>', file_str.find('>', pos+1)+1)+1 );
        
        cout << "\n Student was deleted." << endl;
        
        system ( "pause" );

        break;
       }

      case '4' : // Display Students' Informations
       {
        cout << "ID\t\tName\n"
          << "-----------------------------------\n";
        
        rows = 3; // 2 rows for header, and 1 for pause message at end
        
        
        pos = 0;
        string substr;  // substring for Displaying students' informations

        while (pos != file_str.length())
        {

         substr = file_str.substr( pos, file_str.find('>', pos+1)-pos );

         pos = file_str.find('>', pos+1) + 1;
         
         cout << substr;

         substr = file_str.substr( pos, file_str.find('>', pos+1)-pos );

         pos = file_str.find('>', pos+1) + 1;
         
         cout << "\t\t" << substr << endl;

         if (++rows == 25)
         {
          rows = 3;
          system ( "pause" );
          system ( "cls" );
          cout << "ID\t\tName\n"
            << "-----------------------------------\n";
         }
        }

        cout << "End of the list." << endl;
        system ( "pause" );

        break;
       }
      case '5' : // Exit
       {
        cout << "\n Updating 'Class_List' file..." << flush;

        fs = new fstream ("temp.txt", ios::out);

        if (!fs)
        {
         cout << "\n Can't create 'temp' file, then 'Class_List' file won't be updated." << endl;
         system ( "pause" );

         system( "cls" );
         return 1;
        }

        (*fs) << file_str;

        fs->close();
        delete fs;
        fs=0;

        
           if( remove( "Class_List.txt" ) == -1 )
        {
         if (errno == EACCES)
         {
          cout << "\nCan't delete 'Class_List' file, then Updating is incomplete." << endl;
          system ( "pause" );
          
          system( "cls" );
          return 1;
         }
        }

           if ( rename ("temp.txt", "Class_List.txt") )
        {
         cout << "\nCan't rename 'temp' file, then Updating is incomplete." << endl;
         system( "pause" );
         
         system( "cls" );
         return 1;
        }
       

        system( "cls" );

        return 0;

        break;
       }
      }
     }
    }

    // End of File

  • 2 years ago
    I'm in complete agreement with pcmattman.  By posting the source you've cheated the OP not only academically, but also personally, as he's learned considerably less - if anything - than if you had "nudged" him in the right direction.

  • 2 years ago
    Mohammad Rastkar:

    You've just stopped this person from learning C++ properly. He now has no understanding of WHY the code works, because he's just copied and pasted what you gave him. No-one thinks you're any better at programming by the fact that you can write someone's assignment for them, that's elementary. Next time, please, do not write the entire assignment for him, but give him small nudges in the right direction.

    Furthermore, your code is not commented at all, save a couple of comments pointing out some rather obvious points. The person told us he is still learning C++, and the code you gave, which is wrong in many ways, is in no way helping him. Assignments are not there to be done and handed in, and then forgotten. They are there to be a learning experience.

    It is safe to assume that this person, if he hands in your code, will get caught for plaigarism and receive the relevant penalties. It's just not worth it.

    Teach, don't give.









  • 2 years ago

    Hey Guys, Wait !

    My post is about 40 days after his request, and after my second post there was no reply, then I assumed that he was given up, and I posted my reply to use it other programmers. Even he has been also used that code : I think if a person couldn't do an easy work like that in 40 days, he can't do for ever! because you can get from his post ("now I'm struggling to finish my assignment if possible someone help me finish my work."), that he have the knowledge since he is struggling and wants to finish that not to begin! plus, he said that ("i'v just started to learn visual studio") not C++ itself.

    Aside from above reasons, I think if a person really wants to learn, he can use my code for his learning then! Even if I didn't post that code, there are many code snippets, that just need more 'Copy & Paste's and some stupid human coding to accomplish the whole work!

    In fact, I had problems with storing\getting 'string's from the files, and after some attempts, I could overcome on that (I found some ways on the net, but not completely easy & applicable ones). This request was a good place to share my work with others.

    At The End : Thanks for all of you that have stress on the other's learning, but please think about this : "Assignment doing effects, is related to the one's usage (learning or copy_&_paste!), and the second usage is not others fault that not to view other attempts and learn more!"

    By the way : I think my code is NOT wrong in any way (at least it has no errors)!

  • 2 years ago

    Hi All ,

    My Code sample about this :

    http://www.developerfusion.co.uk/show/6685/

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback