Sponsored Links


Results 1 to 4 of 4

Thread: CS201 Assignment No.1 Solution and Discussion Fall 2014 18th November 2014

  1. #1
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

    CS201 Assignment No.1 Solution and Discussion Fall 2014 18th November 2014

    Sponsored Links1





    CS201 Assignment No.1 Solution and Discussion Fall 2014 18th November 2014



    Assignment Description



    In this assignment, you are provided with a small and simple game like program attached with this assignment named as “GuessGame.cpp”. Your job is to slightly modify this code as desired in this assignment.

    First, you need to understand the working of the given code and execute it in Dev-C++. This program essentially generates a random number in range [1-10] and asks the user to guess that number. Appropriate messages are displayed after user input to give game like feelings. Important part in this code is the following two lines.

    srand(time(NULL));

    secretNumber = rand()%10+1;







    This is also called pseudo random because the same sequence of random numbers can be re-generated if we use the same seed value. In this code, we have used srand() function with parameter time(NULL) to set the seed value as system current time so that we can have a different random number in each execution. In the second line, rand() function simply generates a pseudo random number in range [0 to RAND_MAX] which is divided by 10 to get the remainder (using % operator) in range [0-9], then we simply add 1 to it to get out secrete number in range [1-10].



    Your Task

    Your task is to slightly modify this code in order to produce desired working as shown in “Modified_GuessGame.exe”. This is simply taking two inputs from the user as lower and upper ranges. Next, the program shall generate random number in the range specified by the user. Rest of the working remains the same.

    Hint: You have to use your mathematical skills in order to shift the range of random number from [1-10] to the one specified by user input [lower - upper].

    Screenshot of the desired output:

    Submission

    Sponsored Links

    You are required to submit your solution through LMS in zip format containing two files.

    Your C++ program i.e. .cpp file.
    An MS Word document containing screenshot of your program output/execution. You shall type your own VU_ID and that must be visible in the screenshot.

  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    srand() function

    Description

    The C library function void srand(unsigned int seed) seeds the random number generator used by the function rand.

    Declaration

    Following is the declaration for srand() function.

    void srand(unsigned int seed)

    Parameters

    seed -- This is an integer value to be used as seed by the pseudo-random number generator algorithm.
    Return Value

    This function does not return any value.

    Example

    The following example shows the usage of srand() function.

    #include<iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    int main()
    {
    int i, n;
    time_t t;

    n = 5;

    /* Intializes random number generator */
    srand((unsigned) time(NULL));

    /* Print 5 random numbers from 0 to 50 */
    for( i = 0 ; i < n ; i++ ) {
    coutrand() % 50"\n";
    }

    return(0);
    }



    return(0);

    }

    Sample Result

    38

    45

    29

    29

    47

  3. #3
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,239
    Save this assignment with ur id like mc090205531.cpp and give some comments like
    //user input data
    change the variables and after doing this all then upload to your lms.

  4. #4
    Administrator Xpert's Avatar
    Join Date
    May 2010
    Location
    Jhelum
    Posts
    6,239
    you guys copy this code to notepad and then save with the extention .cpp and then click on edit button there u find replace
    find the variable names and replace with ur variable name it is simple and easy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. FIN722 Assignment No 1 Fall 2014 Solution and Discussion December 2014
    By Vuhelper in forum Assignments & Solutions
    Replies: 0
    Last Post: 12-09-2014, 07:20 PM
  2. Replies: 0
    Last Post: 11-24-2014, 07:43 PM
  3. STA 406 Assignment No.1 Solution Ideas and Discussion Fall 2014
    By Vuhelper in forum Assignments & Solutions
    Replies: 0
    Last Post: 11-20-2014, 02:53 PM
  4. Replies: 1
    Last Post: 11-18-2014, 02:14 PM
  5. MGT111 GDB NO-01 Discussion and Solution Fall 2014 November 2014
    By education-2014 in forum GDB Discussion
    Replies: 0
    Last Post: 11-15-2014, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft