www.vustudents.ning.com

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: Spring 2015

CS201: Introduction to Programming

Total Marks: 20

Due Date: 12/06/2015

Lectures Covered: 7 to 16

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 solution is not in .cpp file format.

Objective

The objective of this assignment is to provide an on hand experience of:

• Learn to code, edit, compile and execute C++ program.
• Learn to use two dimensional array declaration and manipulation.
• Learn to manipulate array with the help of pointer
• Learn to create user defined functions

Guidelines

• Code should properly be indented and well commented.
• Follow C/C++ naming conventions while using variables, functions etc.
• Use only Dev-C++ for this assignment. If you are using any other tool then mention the name of tool and version on top of your code file as comments.

Assignment Description

This assignment is divided into two parts. In first part, you will be provided with sample startup code (attached with this assignment in folder Startup Code) that will populate 2D array with random numbers from 1 to 100 and display on console. Given code also finds the element with maximum and minimum values in array. Output of sample code is given below as Figure 1. We will help you to understand and practice the given code through Adobe Connect lab sessions. For details of lab sessions see announcement of Adobe Connect Lab Sessions.

The displayMaxMinElement( ) function in startup code that is finding maximum and minimum element will help you get the desire output. To get the desired output, you should find the sum of each row and compare with sum of other rows to find which row’s sum is maximum. The same procedure can be used to find row which have minimum sum as compare with other rows in 2D array.

 Figure 1: Sample output of the Startup code Your Task In this part of assignment, you have to modify given startup code and find the row from 2D array whose sum is maximum as compared with sum of other rows. You also have to find the row whose sum is minimum as compared with other rows. Screen shot of the desire output is given in Figure 2. Figure 2: Sample Desired output

Submission

You are required to submit your code through LMS in .cpp file format.

Views: 9461

Replies to This Discussion

hmien sirf all rows m se maximum an minimum sum wali row find krna hai...

plz detai ain bta dyn

The concept of arrays is related to that of pointers. In fact, arrays work very much like pointers to their first elements, and, actually, an array can always be implicitly converted to the pointer of the proper type. For example, consider these two declarations:

 ``12`` `` myarray [20]; * mypointer;``

The following assignment operation would be valid:

 `` `` ``mypointer = myarray;``

After that, `mypointer` and `myarray` would be equivalent and would have very similar properties. The main difference being that `mypointer` can be assigned a different address, whereas `myarray` can never be assigned anything, and will always represent the same block of 20 elements of type `int`. Therefore, the following assignment would not be valid:

 `` `` ``myarray = mypointer;``

Let's see an example that mixes arrays and pointers:

 ``1234567891011121314151617`` ``// more pointers #include std; main () { numbers[5]; * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p+4) = 50; ( n=0; n<5; n++) cout numbers[n] ", "; 0; }`` `10, 20, 30, 40, 50, `

if anyone wants help i can help him understanding the assignment

as the main goal is to understand programming instead of copy pasting :)

yes Rafay guide about ths assignment

explain

Yes Rafay Javed please guide me.

you guys understanding , that how other functions are working ?

and did you read try to make solution?

what and where you guys are facing problem? I'll not give you guys the code as its only 3-4 lines we have to add/edit

so I'll help you guys to solve problem and let you learn programming along , as its the key course

so share here how much code u understand and what do you think about modifying it :)

<id 61007 translation missing>

ye err ata ha jab ye code dev main run krta ho to.

please tell me how can i fix this?

hi, dear agr aap ko easy hoto main apko code txt main bhjta hun , muje code under stand krna hai , nd is main se samj nai lag rahi k program kesy execute hoga , so kindly agr aap .txt mian is code k sath comments paste kr dain to muje samjne main asani ho jay gi.

anisvirtualuni2014@gmail.com

i shall be thankful to u ....

`#include <iostream> #include <stdlib.h> #include <time.h> using namespace std;  void displayMaxMinElement(int array[10][10]) {  int max = 0, min = 100;    for(int i=0;i<10;i++) {            for(int j=0; j<10; j++) {                                  if(array[i][j] <= min)                 min = array[i][j];                              if(array[i][j] >= max)                 max =array[i][j];         }     }             cout"\n\nArray element with maximum value: "maxendl;     cout"Array element with minimum value: "minendlendl;  }  void displayMaxMinRow(int array[10][10]) {   int sum = 0, max = 0, min = 1000, row;     for(int i=0;i<10;i++) {            for(int j=0; j<10; j++) {                  sum = sum + array[i][j];         }                  if(sum <= min)         {             min = sum;                 row = i+1;                 }                   if(sum >= max)             {              max = sum;                 row = i+1;                 }          sum = 0;     }        cout"\n\nRow no. "row" has maximum sum: "maxendl;     cout"Row no. "row" has minimum sum: "minendlendl;        }  void fillBoard(int array[10][10]) {     srand(time(0));     for(int i = 0; i < 10; i++) {         for(int j = 0; j < 10; j++) {             array[i][j] = rand()%100+1;        } } }    void displayBoard(int array[10][10]){     int *ptr = *array;            for(int i = 1; i <= 100; i++) {                cout*ptr"\t";                ptr++;                      if(i%10 == 0)              coutendl;     }     coutendl;     ptr = NULL; }      main() {                int board[10][10] = {0};                   fillBoard(board);          displayBoard(board);       displayMaxMinElement(board);       displayMaxMinRow(board); cout  "Thank you and Luv U brother as u tried to help me,,,! Anis Ur Rehman :)";system("pause");     }    `

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

void displayMaxMinElement(int array[10][10]) {
int max = 0, min = 100;
for(int i=0;i<10;i++) {
for(int j=0; j<10; j++) {

if(array[i][j] <= min)
min = array[i][j];

if(array[i][j] >= max)
max = array[i][j];
}
}
cout"\n\nArray element with maximum value: "maxendl;
cout"Array element with minimum value: "minendlendl;
}

void displayMaxMinRow(int array[10][10]) {
int sum = 0, max = 0, min = 1000, row;
for(int i=0;i<10;i++) {
for(int j=0; j<10; j++) {
sum = sum + array[i][j];
}

if(sum <= min)
{
min = sum;
row = i+1;
}

if(sum >= max)
{
max = sum;
row = i+1;
}
sum = 0;
}
cout"\n\nRow no. "row" has maximum sum: "maxendl;
cout"Row no. "row" has minimum sum: "minendlendl;
}

void fillBoard(int array[10][10]) {
srand(time(0));
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 10; j++) {
array[i][j] = rand()%100+1;
}
}
}
void displayBoard(int array[10][10]){
int *ptr = *array;

for(int i = 1; i <= 100; i++) {
cout*ptr"\t";
ptr++;

if(i%10 == 0)
coutendl;
}
coutendl;
ptr = NULL;
}

main() {

int board[10][10] = {0};

fillBoard(board);
displayBoard(board);
displayMaxMinElement(board);
displayMaxMinRow(board);

system("pause");
}

1

2

3

4

5

Latest Activity

10 minutes ago
arham khan and Technical Guru joined Virtual University of Pakistan
14 minutes ago
Muhammad Bilal liked иαвєєℓ αнмє∂'s discussion Kya hal hain ning awam?
11 hours ago
Technical Guru liked Sana Sunny ツ's discussion we need Chat box at ning
17 hours ago
Technical Guru updated their profile
20 hours ago
yesterday
monaliza and waseem are now friends
yesterday
Zubii joined + M.Tariq Malik's group

Friday