We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

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

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 10813

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Replies to This Discussion

CS201 Out Put

Attachments:

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
// declare and initialize variables
int low = 0, high = 0, secretNumber = 0, userNumber = 0;
int level=0;
int totalAttempts =0;
int currentAttempt=0;

cout"My Student ID is bc140202134"endl;

// get input value for level
cout"There are several levels for this programm, please read the instructions: \n";
cout"Enter 1 for beginner level\n";
cout"Enter 2 for intermediate level \n";
cout"Enter 3 for advance\n\n";

for (int i=0; i<1000; i++)
{
cout"Choice: ";
cin>>level;

if(level == 1)
{
totalAttempts = 3;
break;
}
else if(level == 2)
{
totalAttempts = 4;
break;
}
else if(level == 3)
{
totalAttempts = 5;
break;
}
else
{
cout"You have entered incorrect choice ..... please enter again \n";
continue;
}
}

// 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"\nComputer 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!\n"endl;

for(int i=0; i<totalAttempts; i++)
{
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;
continue;
}
else if(userNumber < secretNumber)
{
cout"Oooppssss...your entered number is too low...Computer won"endl;
continue;
}
else if(userNumber == secretNumber)
{
cout"Wawoooo...Congratulations!...You won"endl;
break;
}
else{
cout"Invalid Input"endl;
break;
}
}

cout "\n\nuserNumber: " userNumber "\n";
cout"Secret Number was: " secretNumberendl;

system("pause");

}

bro thek sy check kro .. 100 % ok hy :-)

check this  100% working

Attachments:

I got 20 marks 

RSS

Latest Activity

Sheraz Ali posted a discussion
19 minutes ago
Imran Khan replied to +¢αяєℓєѕѕ gιяℓ's discussion CS506 - Web Design and Development Assignment No.1 Due Date Nov 15, 2019 in the group CS506 Web Design and Development
1 hour ago
Imran Khan joined + M.Tariq Malik's group
1 hour ago
+ ! ! ! ! Mehαr Mαh꧂ liked + M.Tariq Malik's discussion PSC401 Final Term Papers Spring 2019 (24 August ~ 04 September 2019) & All Solved Past Papers, Solved MCQs & Helping Material
1 hour ago
Hamza Hameed replied to + M.Tariq Malik's discussion CS611 Software Quality Engineering Assignment No 01 Fall 2019 Solution & Discussion Due Date: 15-11-2019 in the group CS611 Software Quality Engineering
2 hours ago
+Umar Amin+ replied to + M.Tariq Malik's discussion Criteria Required for Award Badges, Featured Members & Moderators
2 hours ago
+ !! SARAH replied to MIT's discussion Operating Systems(CS604) Assignment # 01 Deadline Date 16-11-2019 in the group CS604 Operating Systems
2 hours ago
+ !! SARAH joined + M.Tariq Malik's group
2 hours ago
November 2019 replied to + M.Tariq Malik's discussion CS401 Assignment No 01 Fall 2019 Solution & Discussion in the group CS401 Computer Architecture and Assembly Language Programming
3 hours ago
Hamza Hameed updated their profile
3 hours ago
Profile IconHamza Hameed, +.Ãŋɠɜʆḁ.+ and Aijaz khan joined + M.Tariq Malik's group
3 hours ago
Profile IconHamza Hameed and Purple Work joined + M.Tariq Malik's group
3 hours ago
Hamza Hameed joined + M.Tariq Malik's group
3 hours ago
Hamza Hameed joined + M.Tariq Malik's group
3 hours ago
Arham Shah replied to + M.Tariq Malik's discussion CS401 Assignment No 01 Fall 2019 Solution & Discussion in the group CS401 Computer Architecture and Assembly Language Programming
3 hours ago
Arham Shah joined + M.Tariq Malik's group
3 hours ago
khurram us salam replied to + M.Tariq Malik's discussion MGT402 Cost & Management Accounting Online Quiz No 01 Fall 2019 Solution Discussion in the group MGT402 Cost & Management Accounting
3 hours ago
khurram us salam joined + M.Tariq Malik's group
3 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked + ! ! ! ! ! MySterIouS's blog post + Beginning +
3 hours ago
+ ! ! ! ! ! ! ! ! ! AG liked Mani Siddiqui BS VIII's discussion Kash Main Doure Payamber
3 hours ago

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

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