CS201 Assignment 1 Solution and Discssion


  • Cyberian's Gold

    Assignment No. 1
    Semester: Fall 2019
    CS201 – Introduction to Programming Total Marks: 20

    Due Date: November 14, 2019
    Instructions
    Please read the following instructions carefully before submitting assignment:
    It should be clear that your assignment will not get any credit if:

    o Assignment is submitted after due date.
    o Submitted assignment does not open or file is corrupt.
    o Assignment is copied (From internet/students).

    Software allowed to develop Assignment

    • Dev C++

    Objectives:
    To enable students to understand and practice the concepts of:
    • Variables and operators
    • Loops or repetition structures
    • If-else statements
    • Functions
    • Random number generation
    • Control random number in specific range

    Assignment Submission Instructions
    You have to submit only.cpp file on the assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.
    Please note again, assignment submitted other than .cpp format will get zero marks.

    Assignment

    Programming is a nice tool which can be used to make our life easier. With the help of programming we can do many things auto generated and efficiency. As a programmer first task of this semester is given to you is develop a console-based application for school teachers. This application will auto generate questions for Grades 1, 2, 3, 4 and 5. Using this application teacher will be able to give different paper to each student.

    Assignment Statement:
    Write a menu-based program in C++ that will take input from user(teacher) and fulfill following requirements.

    • There should be a menu that allow to select grade of class.
    • Created questions should be mixed type (addition and subtraction).
    • User will give number of questions that will be generated for a paper.
    • Ratio of addition and subtraction questions is not fixed. It will random, a paper can have more questions of one type than other. See sample output screenshot.
    • Number of minimum and maximum digits in paper of grade 1 will be two.
    • Number of minimum and maximum digits in paper of grade 2 will be three.
    • Number of minimum and maximum digits in paper of grade 3 will be four.
    • Number of minimum and maximum digits in paper of grade 4 will be five.
    • Number of minimum and maximum digits in paper of grade 5 will be six.
    • Screen shot of required application is given below as simple output.
    • Most critical requirement is, the operand (number) on left side of subtraction sign must be larger than the number on right side of sign (operator). This requirement is highlighted in sample screenshot too.
    • In case of addition operation, the operand (number) on left side of addition sign can be larger or smaller from the number on right side of sign (operator).

    Solution instructions:
    • Variables, loops, if-else, rand() function with % operator, functions (one which return a value and one which do not return a value) will help you to solve the problem.
    • Use rand() function to generate a random number. You can control the range of number with the help of modulus (%) operator.
    • To use rand() function you must include “stdlib.h” header file.
    • To control the range of random number rand() % N can help, if value of N will be 100 then range of randomly generated number will be 0 to 99.
    • If you want to control the range of random number between 10 to 19 then following formula will help.
    o [10 + rand() % (19 – 10 + 1)]

    Sample output:
    7fc82ca0-0224-4978-9a93-24adafab2eab-image.png

    Lectures Covered: (Lecture # 1- 10) and Solution Deadline: (November 14, 2019).


  • Cyberian's Gold

    Solution Code

    #include <iostream>
    #include <iomanip>
    #include <stdlib.h>
    using namespace std;
    
    int selectGrade(){
    	int grade = 0;
    	
    	cout<<"1 : First Grade\n";
    	cout<<"2 : Second Grade\n";
    	cout<<"3 : Third Grade\n";
    	cout<<"4 : Fourth Grade\n";
    	cout<<"5 : Fifth Grade\n";	
    	
    	cout<<"\nPlease select grade, use numbers 1 to 5: ";
    	
    	do {
    		cin>>grade;
    		if(grade >= 1 && grade <= 5){
    			break;
    		}
    		else {
    			cout<<"\nGrade must be between 1 and 5\n";
    			cout<<"Invalid choice, please select correct grade: ";
    		}
    	} while(true);
    	return grade;	
    }
    
    void createQuestions(int l, int u, int q){
    	
    	int firstNum = 0, secondNum = 0;
    	
    	for(int i = 1; i <= q; i++){
    		
    		firstNum = l + (rand() % (u - l + 1));
    		secondNum = l + (rand() % (u - l + 1));
    			 
    		cout<<setw(2)<<i<<".";
    		
    		if(rand() % 2 == 0){
    			cout<<"  ("<<firstNum<<" + "<<secondNum<<") = ______\t\t";;
    		}
    		else{
    			if(firstNum > secondNum) {
    				cout<<"  ("<<firstNum<<" - "<<secondNum<<") = ______\t\t";
    			}
    			else{
    				cout<<"  ("<<secondNum<<" - "<<firstNum<<") = ______\t\t";
    			}			
    		}
    		
    		if(i % 3 == 0){
    			cout<<"\n";
    		}
    	}	
    }
    
    void generatePaper(int grade, int questions) {
    	
    	int lowerLimit, Upperlimit;
    	
    	if(grade == 1){
    		lowerLimit = 10; 
    		Upperlimit = 99;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 2){
    		lowerLimit = 100; 
    		Upperlimit = 999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 3){
    		lowerLimit = 1000; 
    		Upperlimit = 9999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 4){
    		lowerLimit = 10000; 
    		Upperlimit = 99999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 5){
    		lowerLimit = 100000; 
    		Upperlimit = 999909;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    }
    
    main(){
    	
    	int grade = 0, numQuestions = 0;
    	grade = selectGrade();
    	
    	cout<<"Enter number of questions you want to generate: ";
    	cin>>numQuestions;
    	
    	cout<<endl;
    	generatePaper(grade, numQuestions);	
    	cout<<endl;
    	system("pause");
    }
    
    
    

  • Cyberian's Gold

    Solution Code

    #include <iostream>
    #include <iomanip>
    #include <stdlib.h>
    using namespace std;
    
    int selectGrade(){
    	int grade = 0;
    	
    	cout<<"1 : First Grade\n";
    	cout<<"2 : Second Grade\n";
    	cout<<"3 : Third Grade\n";
    	cout<<"4 : Fourth Grade\n";
    	cout<<"5 : Fifth Grade\n";	
    	
    	cout<<"\nPlease select grade, use numbers 1 to 5: ";
    	
    	do {
    		cin>>grade;
    		if(grade >= 1 && grade <= 5){
    			break;
    		}
    		else {
    			cout<<"\nGrade must be between 1 and 5\n";
    			cout<<"Invalid choice, please select correct grade: ";
    		}
    	} while(true);
    	return grade;	
    }
    
    void createQuestions(int l, int u, int q){
    	
    	int firstNum = 0, secondNum = 0;
    	
    	for(int i = 1; i <= q; i++){
    		
    		firstNum = l + (rand() % (u - l + 1));
    		secondNum = l + (rand() % (u - l + 1));
    			 
    		cout<<setw(2)<<i<<".";
    		
    		if(rand() % 2 == 0){
    			cout<<"  ("<<firstNum<<" + "<<secondNum<<") = ______\t\t";;
    		}
    		else{
    			if(firstNum > secondNum) {
    				cout<<"  ("<<firstNum<<" - "<<secondNum<<") = ______\t\t";
    			}
    			else{
    				cout<<"  ("<<secondNum<<" - "<<firstNum<<") = ______\t\t";
    			}			
    		}
    		
    		if(i % 3 == 0){
    			cout<<"\n";
    		}
    	}	
    }
    
    void generatePaper(int grade, int questions) {
    	
    	int lowerLimit, Upperlimit;
    	
    	if(grade == 1){
    		lowerLimit = 10; 
    		Upperlimit = 99;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 2){
    		lowerLimit = 100; 
    		Upperlimit = 999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 3){
    		lowerLimit = 1000; 
    		Upperlimit = 9999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 4){
    		lowerLimit = 10000; 
    		Upperlimit = 99999;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    	else if(grade == 5){
    		lowerLimit = 100000; 
    		Upperlimit = 999909;
    		createQuestions(lowerLimit, Upperlimit, questions);
    	}
    }
    
    main(){
    	
    	int grade = 0, numQuestions = 0;
    	grade = selectGrade();
    	
    	cout<<"Enter number of questions you want to generate: ";
    	cin>>numQuestions;
    	
    	cout<<endl;
    	generatePaper(grade, numQuestions);	
    	cout<<endl;
    	system("pause");
    }
    
    
    


Jan
27
(2 Views / 0 Upvotes)
0 Replies

10. COGNITIVE | CLOUD COMPUTING
709a4b58-3423-4963-9e29-bd995cadb5fc-image.png
Cloud computing is the on-demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. The term is generally used to describe data centers available to many users over the Internet.

Aug
19
(33 Views / 0 Upvotes)
2 Replies

Dear Students if you have any query regarding Final Term Exam
Please Feel Free to Ask Cyberian’s

Sep
18
(29 Views / 0 Upvotes)
0 Replies

یہ ۵ جی کیا ہے؟
دوسرے سیلولر نیٹ ورکوں کی طرح ، 5 جی نیٹ ورک سیلولرکلز کرنے کے انتظامات کو استعمال کرتے ہیں جو اپنے ڈومین کو علاقوں میں الگ کرتے ہیں اور ریڈیو لہروں کے ذریعہ انکوڈڈ معلومات بھیجتے ہیں۔ ہر سیل سائٹ کو سسٹم کی ریڑھ کی ہڈی سے وابستہ ہوتا ہے، اس سے قطع نظر کہ وائرڈ یا ریموٹ بیک ہاؤل ایسوسی ایشن کے ذریعے۔ 5 جی نیٹ ورک ایک قسم کی انکوڈنگ کا استعمال کریں گے جسے آف ڈی ایم کہتے ہیں ، جو انکوڈنگ کی طرح ہے جس میں 4 جی ایل ٹی ای کام کرتا ہے۔ تاہم ، ہوائی انٹرفیس کا مقصد...

Dec
17
(15 Views / 0 Upvotes)
21 Replies

Live Updates:
Pakistan’s former dictator Pervez Musharraf was on Tuesday sentenced to loss of life in the excessive treason case by way of a special court docket here, turning into the first navy ruler to get hold of the capital punishment in the country’s history.
567e9088-009d-47b4-a689-988ca233129e-image.png
A three-member bench of the special courtroom, hea...

Sep
6
(44 Views / 0 Upvotes)
0 Replies

فیس بک ڈیٹنگ اپنی پسند کی چیزوں کے ذریعہ پیار تلاش کرنا آسان بناتا ہے - اپنی مشترکہ چیزوں ، جیسے مفادات ، واقعات اور گروہوں کے ذریعہ معنی خیز تعلقات شروع کرنے میں مدد کرتا ہے۔ یہ ڈیٹنگ پروفائل بنانے میں کام کرتا ہے اور آپ کو زیادہ مستند نظر دیتا ہے کہ کوئی کون ہے۔
a5068e0f-944c-4e27-b28d-bec69b167543-image.png
آج ، ہم امریکہ میں فیس بک ڈیٹنگ کا آغاز کر رہے ہیں۔ ہم لوگوں کو انسٹاگرام ...

Aug
22
(101 Views / 1 Upvotes)
1 Replies

I’d say as a blogger and a IT student that it’s a great achievement for a local operator. As we know, communication is expanding globally and we do need faster networks to communicate.
IMG_20190822_194412.jpg

I’d say as a blogger and a IT student that it’s a great achievement for a local operator. As we know, communication is expanding globally and we do need faster netwo...

Sep
6
(15 Views / 0 Upvotes)
0 Replies

b244dd88-39a0-47bb-95f5-5af7cf1991c7-image.png

Image: justin sullivan / Getty Images

کمپنی نے منگل کو اعلان کیا کہ فیس بک اپنی چہرے کی شناخت کی خصوصیات کو بند کرنے میں آسان تر بنا رہا ہے اور اب وہ خود بخود نئے صارفین کو فیس ٹیگنگ کا انتخاب نہیں کرے گا۔

فیس بک اپنے صارفین کے اپ لوڈ کردہ فوٹو میں چہروں کی شناخت کے لئے چہرے کی پہچان کا استعمال...

Aug
6
(22 Views / 0 Upvotes)
0 Replies

Join the celebration at the all-new Apple Aventura.
Our new location opens Saturday, August 10 at 10:00 a.m.
Join us for the grand opening of our new store - located in a bigger space right across from the Aventura Slide Tower. Come celebrate your creativity during opening weekend with free Today at Apple sessions in music, photography, art, and more. And enjoy our vibrant Latin Music Fridays happening throughout the month of August.

Sep
6
(21 Views / 0 Upvotes)
0 Replies

آئی فونز اور ہیکرز پر حالیہ ہیک حملے کی وجہ سے جس کو دنیا میں سب سے زیادہ محفوظ فون سمجھا جاتا تھا اس کی سیکیورٹی کو نظرانداز کیا جارہا ہے۔ کیا آپ کو ایسی کوششوں سے بچایا گیا ہے؟ آپ خود کو ڈیجیٹل طور پر کیسے محفوظ کرسکتے ہیں؟

آئی فون ہیکنگ آپریشنوں کی ایک حالیہ لہر جنہوں نے جنوری تک “ایک ہفتے میں ہزاروں صارفین” کو متاثر کیا ، گوگل کے پروجیکٹ زیرو سیکیورٹی ٹیم کے محققین نے انکشاف کیا ہے۔ ایپل کے آئی فونز کو بڑے پیمانے پر وہاں کے سب سے محفوظ آلات سمجھا جاتا ہے۔ واقع...

Jul
31
(143 Views / 0 Upvotes)
1 Replies

To register your device, go to this link and create your account as an individual user. Select your user type International traveler
On submission of Signup form, a confirmation link will be received in your provided email address. Cl...

    Recent Topics


  • 1
  • 2
  • 3
  • 2
  • 3
  • 11
  • 6
  • 3
| DMCA.com Protection Status