Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Assignment No. 02
Semester: Fall 2014

CS201: Introduction to Programming

Total Marks: 20

Due Date: 12-12-2014

Lectures covered: 6 to 12

 

Please read the following instructions carefully before submitting assignment.

It should be clear that your assignment will not get any credit if:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)
  • Assignment is in any other format than .CPP

 

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

Table 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.

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 messages.

Submission  

You are required to submit your solution file in .CPP file only.

 

Fall%202014_CS201_2.doc

Views: 10995

Replies to This Discussion

ap log ye optin na dain ..
yuor choice wala .

farri yeh option ni khatm ni kr skty q k sample out put main yeh hai is liay yeh zarori hai

CS201 Assignment#02 Solution

#include <iostream.h>
#include<conio.h>
void function(int rang , int x)
{
int user[3];
int c = 1;
int secret = 0;
bool ch = true ;
cout"Computer is calculating a random secret number in the given range ...";
srand(time(NULL));
secret = rand()%(rang+1);
cout"Done!" endlendl;
for (int i = 1 ;i <=x; i++)
{
cout"\nTurn "i"of "x" : "endl;
cout"Please guesss the secret number in the range [1 - "rang"]: ";
cin>>user[i];
if(user[i] > secret){
cout"Oooppssss...your entered number is too high.. “endl;
ch = false;
}
else if(user[i] < secret){
cout"Oooppssss...your entered number is too low... "endl;
ch = false;
}
else if(user[i] == secret) {
cout"Wawoooo...Congratulations!...You won "endl;
cout"You found the secret number in "c" tries.";
ch = true;
break;
}
c++;
}
if(ch == false )
{
cout"You don't have more turns..... Computer won." endl;
}
cout"\n Your choice was "user[3];
cout"\n Secret Number was: "secretendlendl;
}
main(){
int ch ;
cout"Enter 1 for beginner level\n";
cout"Enter 2 for intermediate level\n";
cout"Enter 3 for advance level\n";
Loop:
cout"\n\nChoice: ";
cin>>ch;
if(ch== 1)
{
function(20 ,3);
}
else if(ch == 2)
{
function(50 ,4);
}
else if(ch == 3)
{
function(100 ,5);
}
else
{
cout"\n Your entered choice is incorrect. Please enter again \n";
goto Loop;
}
system("pause");
}

is coad main problem hai ..... baki main ny try ni kiay

CS201 Assignment 12 Dec 2014

#include
#include
#include
using namespace std;
int userChoiseLevel(int,int);
int randomNumGenrated(int);
int vaildNumberChecker();
int main () {
int randomNumber, validNumber;
validNumber=vaildNumberChecker();
coutendl;
randomNumber = randomNumGenrated(validNumber);
cout" "endlendl;
userChoiseLevel(validNumber+2,randomNumber); system("pause");}
//function start
int vaildNumberChecker(){ cout"\t\t\t\tAttension !\n\tthis Assignment is completed by saadi.muhammad43@gmail.com\n";
cout"Enter 1 for Biginner Level "endl;
cout"Enter 2 for Intermadiate Level "endl;
cout"Enter 3 for Advance Level "endlendl;
cout"Choice : ";
int v; cin>>v;
if (v == 1 || v == 3 || v == 2){ return(v);}
else {
cout"Your Enter Choice is incorrect. Please enter again "endlendl"Choice :";
int i=1;
do {
int s; cin>>s;
if (s<1 || s>3){cout"Your Enter Choice is incorrect. Please enter again \n"endl"Choice :";}
else { return(s); break; } i++;} while(i>1); } }
//22222222222222222
int userChoiseLevel(int x, int rnnd) {
int c[x];
int z, i=0;
do {
cout"Turn "i+1" of "x": \n";
if(x==3){cout"please guess the secrect number in range[1 - 20] : ";}
else if (x==4){cout"please guess the secrect number in range[1 - 50] : ";}
else{cout"please guess the secrect number in range[1 - 100] : ";}


cin>>z;
if (z"\nOooppsss.....your enter number is low...\n\n\n";}
else {cout"Oooppsss....your enter is high...\n\n\n";}
if(z != rnnd){ c[i]=z;} i++;

}while(z != rnnd && i
if (z == rnnd){cout"waaaoooo.....Congratulation...you won\n\nyou find the secret number in "i" tries\n";
cout"your Choice was : "z"\n""\secret number was : "z"\n\n\n\n\n";}
else {cout"You Don't have more turnes.....computer won. ";
cout"\nyour Choice was : "z"\n""\secret number was : "rnnd"\n\n\n\n\n";
}
}
// 3333333333333

int randomNumGenrated(int j){
cout"Computer is calculating Secret Number in given range........done! "endlendl;
int lnt, rannd;
if (j==1){ cout" ";
srand(time(NULL));
rannd = (rand() % 20+1);
return(rannd);}
else if (j==2 ){ cout" ";
srand(time(NULL));
rannd = (rand() % 50+1); return(rannd);}
else if (j==3){ cout" ";
srand(time(NULL));
rannd = (rand() % 100+1); return(rannd);}}

CS201 Assignment#02 Solution

#include <iostream.h>
#include<conio.h>
void function(int rang , int x)
{
int user[3];
int c = 1;
int secret = 0;
bool ch = true ;
cout"Computer is calculating a random secret number in the given range ...";
srand(time(NULL));
secret = rand()%(rang+1);
cout"Done!" endlendl;
for (int i = 1 ;i <=x; i++)
{
cout"\nTurn "i"of "x" : "endl;
cout"Please guesss the secret number in the range [1 - "rang"]: ";
cin>>user[i];
if(user[i] > secret){
cout"Oooppssss...your entered number is too high.. “endl;
ch = false;

else if(user[i] < secret){
cout"Oooppssss...your entered number is too low... "endl;
ch = false;

else if(user[i] == secret) {
cout"Wawoooo...Congratulations!...You won "endl;
cout"You found the secret number in "c" tries.";
ch = true;
break;
}
c++;
}
if(ch == false )
{
cout"You don't have more turns..... Computer won." endl; 
}
cout"\n Your choice was "user[3];
cout"\n Secret Number was: "secretendlendl;
}
main(){
int ch ;
cout"Enter 1 for beginner level\n";
cout"Enter 2 for intermediate level\n";
cout"Enter 3 for advance level\n";
Loop:
cout"\n\nChoice: ";
cin>>ch;
if(ch== 1)
{
function(20 ,3);
}
else if(ch == 2)
{
function(50 ,4);
}
else if(ch == 3)
{
function(100 ,5);
}
else 
{
cout"\n Your entered choice is incorrect. Please enter again \n";
goto Loop;
}
system("pause");
}




final solution for all sweet frnds :-)

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void function(int rang , int x)
{
int user;
int c = 1;
int secret = 0;
bool ch = true ;
cout"Computer is calculating a random secret number in the given range ...";
srand(time(NULL));
secret = rand()%(rang+1);
cout"Done!"endlendl;
for (int i = 1 ;i <=x; i++)
{
cout"\nTurn "i"of "x" :"endl;
cout"Please guesss the secret number in the range [1 - "rang"]: ";
cin>>user;
if(user> secret)
{
cout"Oooppssss...your entered number is too high.. "endl;
ch = false;
}
else if(user < secret)
{
cout"Oooppssss...your entered number is too low... "endl;
ch = false;
}
else if(user == secret)
{
cout"Wawoooo...Congratulations!...You won "endl;
cout"You found the secret number in "c" tries.\n";
ch = true;
break;
}
c++;
}
if(ch == false )
{
cout"You don't have more turns..... Computer won."endl;
}
cout"\nYour choice was "user;
cout"\nSecret Number was: "secretendlendl;
}
main(){

int ch ;
cout"Enter 1 for beginner level\n";
cout"Enter 2 for intermediate level\n";
cout"Enter 3 for advance level\n";
Loop:
cout"\n\nChoice: ";
cin>>ch;
if(ch== 1)
{
function(20 ,3);

}
else if(ch == 2)
{
function(50 ,4);

}
else if(ch == 3)
{
function(100 ,5);

}
else
{
cout"\nYour entered choice is incorrect. Please enter again\n";
goto Loop;

}

system("pause");

}

yeh glat haiis main b wohi problem hai  . cout your choise was user yeh wrong hai

cout your choise was user main user ki jagha kuch oor aana hai

RSS

Looking For Something? Search Below

Latest Activity

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service