Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS201 Assignment No.1 Solution and Discussion Fall 2014 18th November 2014
#1



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

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.

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#2
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

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#3
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.
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,196 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,086 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,595 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,278 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,868 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,093 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,907 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,526 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,557 05-15-2015, 03:52 AM
Last Post: Xpert
  Assignment No. 01 Spring 2015 Information Systems CS507 idea solution spring 2015 Xpert 0 2,445 05-15-2015, 03:49 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)