Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS201-Introduction to Programming Assignment No.2 Due Date 12 December 2014
#1

CS201-Introduction to Programming Assignment No.2, Solutions and Discussions, Fall 2014 Due Date: 12-Dec-2014

Objective:

The objective of this assignment is to learn, practice and understand practical usage of

Loops
Functions
Guidelines:

Code should properly be indented and well commented.
Use only Dev-C++ for this assignment. If you are using any other tool then mention it at top of your code file as comments.
You are recommended to submit only single CPP file. Don’t zip it or paste code in MS word file.
Assignment Description

This assignment is based on our previous assignment and you can use solution of Assignment#1 as a startup code. In Assignment#1, user was asked only once to guess the random number generated by computer. Here, you are required to enhance its capability by introducing three levels (Beginner, Intermediate, and Advance). The range and number of tries/attempts in each level is given below.

Level Secret Number Range No. of attempts
Beginner 1-20 3
Intermediate 1-50 4
Advance 1-100 5


able 1: Secret number range and no. of attempts for different Levels.

It means that if the user selects (say for example) Intermediate level, then program shall generate a random number in ranges 1-50 and asked user to guess that number in 4 attempts. After every wrong attempt, computer will tell the user that your guess was either below or above as before which will help user to make intelligent guess in next attempt.

Sample working of the desired program is shown in attached video file “Sample_Output.mp4”.

Solution Guidelines

You can complete this assignment by using three functions and brief description of each function is given below:

1. selectLevel: This function will essential take input from user to choose desired level. It will also check if the user provides valid input i.e. in range 1 and 3, otherwise appropriate message shall be displayed like shown in the screenshot below.

[Image: attachment.php?attachmentid=24310&stc=1]

2. generateSecretNumber: This function will generate a secret random number as per user selected level in the range given in Table 1.

3. guessSecretNumber: This function will allow user to make multiple attempts as per user selected level to guess the secret number along with appropriate message


Attached Files
.jpg   sample.jpg (Size: 17.45 KB / Downloads: 2,670)
Reply
#2
i dont think that array can be used in this code

i think we should proceed as below

1. define function for selection of level.

2. take input from user for level in main

3. call function by value

4. use the input retrieved from function to calculate secret number

5.take input from user guess

6. compare the secret number

7. display results

use while loop to give number of tries

calculate number of tries = level +2

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#3
example of array in assembly language that is easy to understand. i sure after reading this example you will be able to write your own program. please read this carefully
global _start ;must be declared for linker (ld)
_start:

mov eax,3 ;number bytes to be summed
mov ebx,0 ;EBX will store the sum
mov ecx, x ;ECX will point to the current element to be summed
top: add ebx, [ecx]
add ecx,1 ;move pointer to next element
dec eax ;decrement counter
jnz top ;if counter not 0, then loop again
done:
add ebx, '0'
mov [sum], ebx ;done, store result in "sum"
display:
mov edx,1 ;message length
mov ecx, sum ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
global x
x:
db 2
db 4
db 3
sum:
db 0

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply
#4
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
main(){

// declare and initialize variables
int low = 0, high = 0, secretNumber = 0, userNumber = 0;

cout"My Student ID is BC123456789"endl;

// get input value for lower range
cout"Enter lower range: ";
cin>>low;

// get input value for upper range
cout"Enter upper range: ";
cin>>high;

// validation check: lower range must be greater than zero
if(low < 1){
cout"The value of lower range must be greater than zero(0)"endl;
system("pause"); // pause output screen
exit(0); // exit the program
}

// validation check: high range must be greater than low range
else if( high <= low){
cout"The value of high range must be greater than low range"endl;
system("pause"); // pause output screen
exit(0); // exit the program
}

cout"Computer is calculating a random secret number in the given range...";

// setting random seed value with current system time
srand(time(NULL));

// generating secret number
secretNumber = low + (rand() % (high - low + 1 ) );
cout"Done!"endlendl;

cout"Please guesss the secret number in the range ["low" - "high"]: ";
cin>>userNumber;

if(userNumber > secretNumber){
cout"Oooppssss...your entered number is too high...Computer won"endl;
}
else if(userNumber < secretNumber){
cout"Oooppssss...your entered number is too low...Computer won"endl;
}
else if(userNumber == secretNumber) {
cout"Wawoooo...Congratulations!...You won"endl;
}
else{
cout"Invalid Input"endl;
}
coutuserNumberendl;
cout"\n\nSecret Number was: "secretNumberendlendl;

system("pause");

}

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)