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

M.Tahir  thnkx fr idea of solution plz ye bta dyn k hm is mai maximum r minimum value change kr dyn tu ye change ho jya ga kindly bta dyn .

#include <cstdlib>
#include <iostream>
#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: " max endl;
cout "Array element with minimum value: " min endl endl;
}

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)
cout endl;
}
cout endl;
ptr = NULL;
}

void find(int array[10][10])
{
int SumOfEachRow = 0;
int MaximumSumOfAll = 0;
int MaximumRow = 0;
int MinimumRow = 0;
int MinimumSumOfAll = 10000;
for(int i = 0; i < 10; ++i)
{
SumOfEachRow = 0;
for(int j = 0; j < 10; ++j)
{
SumOfEachRow += array[i][j];
}
if (SumOfEachRow >= MaximumSumOfAll)
{
MaximumSumOfAll = SumOfEachRow;
MaximumRow = i + 1;
}
if (SumOfEachRow <= MinimumSumOfAll)
{
MinimumSumOfAll = SumOfEachRow;
MinimumRow = i + 1;
}
}
cout "Row No. " MaximumRow " has maximum sum: " MaximumSumOfAll endl;
cout "Row No. " MinimumRow " has minimum sum: " MinimumSumOfAll endl endl;
}

int main(int argc, char *argv[])
{int board[10][10] = {0};
fillBoard(board);

displayBoard(board);
displayMaxMinElement(board);

find(board);

system("PAUSE");
return 0;
}

#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 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;
}

void find(int array[10][10])
{
int SumOfEachRow = 0;
int MaximumSumOfAll = 0;
int MaximumRow = 0;
int MinimumRow = 0;
int MinimumSumOfAll = 10000;
for(int i = 0; i < 10; ++i)
{
SumOfEachRow = 0;
for(int j = 0; j < 10; ++j)
{
SumOfEachRow += array[i][j];
}
if (SumOfEachRow >= MaximumSumOfAll)
{
MaximumSumOfAll = SumOfEachRow;
MaximumRow = i + 1;
}
if (SumOfEachRow <= MinimumSumOfAll)
{
MinimumSumOfAll = SumOfEachRow;
MinimumRow = i + 1;
}
}
cout "Row No. " MaximumRow " has maximum sum: " MaximumSumOfAll endl;
cout "Row No. " MinimumRow " has minimum sum: " MinimumSumOfAll endl endl;
}

main()
{

int board[10][10] = {0};
fillBoard(board);

displayBoard(board);
displayMaxMinElement(board);

find(board);

system("pause");
}

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

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\n Array Element with maximum value:"maxendl;

cout"Array Element with Minimum valaue: " minendlendl;

cout"Row No.8 has maximum sum:"array[6][0]+array[6][1]+array[6][2]+array[6][3]+array[6][4]+array[6][5]+array[6][6]+array[6][7]+array[6][8]+array[6][9]endl;

cout"Row No.7 has minumum sum:"array[7][0]+array[7][1]+array[7][2]+array[7][3]+array[7][4]+array[7][5]+array[7][6]+array[7][7]+array[6][8]+array[6][9]endl;

}

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=0;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);

system("pause");

return 0;

}

void displayrow(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;
: "row"\t""Maximum Sum Is = "maxendl"Row n: "row"\t"" Minimum Sum Is = "minendlendl;
}

Aik hi row m max and min ni dhondna

each row agr max hai thn min another hna chaiye..

in continuing of my previous post,

• add array with index of 10 values in the displayMaxMinElement function,
• find out the sum of row by using loop.
• then make condition to collect greater value and lowest value(sum) of row.
• the result will be find

koe cmplete solutn bta dy plzzz......

Sir i need help.assignment kon sy leactures main sy hai?

*****

#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"\nArray element with maximum value: "maxendlendl;
cout"Array element with minimum value: "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;
}

void find(int array[10][10])
{
int SumOfEachRow = 0;
int MaximumSumOfAll = 0;
int MaximumRow = 0;
int MinimumRow = 0;
int MinimumSumOfAll = 10000;
for(int i = 0; i < 10; ++i) {
SumOfEachRow = 0;
for(int j = 0; j < 10; ++j) {
SumOfEachRow += array[i][j];
}
if (SumOfEachRow >= MaximumSumOfAll) {
MaximumSumOfAll = SumOfEachRow;
MaximumRow = i + 1;
}
if (SumOfEachRow <= MinimumSumOfAll) {
MinimumSumOfAll = SumOfEachRow;
MinimumRow = i + 1;
}
}
cout "Row No. " MaximumRow " has maximum sum: " MaximumSumOfAll endl;
cout "Row No. " MinimumRow " has maximum sum: " MinimumSumOfAll endl endl;
}

main() {

int board[10][10] = {0};
fillBoard(board);

displayBoard(board);
displayMaxMinElement(board);

find(board);

system("pause");
}

#include
#include
#include
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"\nArray element with maximum value: "maxendlendl;
cout"Array element with minimum value: "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;
}

void find(int array[10][10])
{
int SumOfEachRow = 0;
int MaximumSumOfAll = 0;
int MaximumRow = 0;
int MinimumRow = 0;
int MinimumSumOfAll = 10000;
for(int i = 0; i < 10; ++i) {
SumOfEachRow = 0;
for(int j = 0; j < 10; ++j) {
SumOfEachRow += array[i][j];
}
if (SumOfEachRow >= MaximumSumOfAll) {
MaximumSumOfAll = SumOfEachRow;
MaximumRow = i + 1;
}
if (SumOfEachRow <= MinimumSumOfAll) {
MinimumSumOfAll = SumOfEachRow;
MinimumRow = i + 1;
}
}
cout "Row No. " MaximumRow " has maximum sum: " MaximumSumOfAll endl;
cout "Row No. " MinimumRow " has maximum sum: " MinimumSumOfAll endl endl;
}

main() {

int board[10][10] = {0};
fillBoard(board);

displayBoard(board);
displayMaxMinElement(board);

find(board);

system("pause");
}

1

2

3

4

## Latest Activity

Muhammad Bilal liked иαвєєℓ αнмє∂'s discussion Kya hal hain ning awam?
10 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
Technical Guru is now a member of Virtual University of Pakistan
20 hours ago
yesterday
monaliza and waseem are now friends
yesterday
Zubii joined + M.Tariq Malik's group

### MTH401 Differential Equations

Friday
Zubii joined + M.Tariq Malik's group

Friday