Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

Assignment No. 2 Semester: Fall 2019

CS201 – Introduction to Programming

Total Marks: 20

 

Due Date:

02-12-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:

In this assignment, the students will learn:

  • How to fill / populate a two-dimensional array using random numbers.
  • How to write user defined functions and pass an array to them as parameter.
  • How to implement switch statement to process specific options.
  • How to compare elements of array.
  • How to find transpose of an array.

 

Assignment Submission Instructions

You are required to submit only .cpp file on the assignments interface of CS201 at VU-LMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.

 

 

Lectures Covered: This assignment covers Lecture # 11-15.

Deadline: The deadline to submit your assignment solution is 02-12-2019. Your assignment must be submitted within the due date through VU-LMS. No assignment will be accepted through email after the due date.

 

Views: 2208

Attachments:

Replies to This Discussion

CS201 Introduction to Programming Assignment 1 Solution Fall 2019


Please check this ... it's working 

#include <iostream>
#include <ctime> // For time()
#include <cstdlib> // For srand() and rand()
#include <iomanip>
#include <algorithm>

using namespace std;
int table[10][10] = {0,0};
const int row=10;
const int column=10;
const int flag = 0;
void poulateArray(){
srand(time(0)); // Initialize random number generator.


for(int r=0; r<row; r++)//row
{
for(int c=0; c<column; c++)
{
table [r][c] = (rand()%100) + 1;
}
}
cout "Array is poulated" endl;
};
void showElements (){

if(table[flag][flag] == 0){
cout "Array is empty , first poulate it by pressing 1" endl;
}
else
{
for(int r=0; r<row; r++)//row
{
for(int c=0; c<column; c++)
{
cout table [r][c] "\t";
}
cout endl;
}
}


};
void showLargestElement (){
int temp;
int max = 0;
int indexRow;
int indexColumn;
if(table[flag][flag] == 0){
cout "Array is empty , first poulate it by pressing 1" endl;
}else{

for(int r=0; r<row; r++)//row
{
for(int c=0; c<column; c++)
{
temp = table[r][c];
if(max <= temp){
max = temp;
indexRow = r+1;
indexColumn = c+1;
}
}//second
}//first loop
cout "the max value is" max " which is on Row" indexRow " and cloumn" indexColumn endl;
}
};
void transposeArray (){
int copyArray[10][10];
if(table[flag][flag] == 0){
cout "Array is empty , first poulate it by pressing 1";
}else{

for(int r=0; r<row; r++)//row
{
for(int c=0; c<column; c++)
{
copyArray[c][r]= table[r][c];

}//second
}//first loop

for(int r=0; r<row; r++)//row
{
for(int c=0; c<column; c++)
{
cout copyArray [r][c] "\t";
}
cout endl;

}
}
};

int main()
{
int choice;
bool isTrue = true;
while(isTrue)
{
cout "1.Press 1 to populate a two-dimensional array with integers from 1 to 100." endl;
cout "2.Press 2 to display the array elements." endl;
cout "3.Press 3 to display the largest element present in the array along with its row and column index." endl;
cout "4.Press 4 to find and show the transpose of the array." endl;
cout "Please select an option , use number from 1 to 5 ";
cin >> choice;
cout "--------------------------------------------------------" endl;
switch(choice){
case 1 : poulateArray();
break;
case 2 : showElements();
break;
case 3 : showLargestElement();
break;
case 4 : transposeArray();
break;
default : isTrue = false;
break;
}
}

return 0;
}

Sir ya assign mjhy ning k member ny send ki thi.or mane ider post kr di.

CS201 Introduction to Programming Assignment 1 Solution Fall 2019

#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));
   
  coutsetw(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;
 
 coutendl;
 generatePaper(grade, numQuestions); 
 coutendl;
 system("pause");
}

RSS

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

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