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

www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

# Solution of assignment no 2 CS201 Prepared by: Tahir Ramzan

For any assignment related  question feel free to contact me at: tahirramzan1@yahoo.com (03155515767)

+ 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?

Views: 1965

.

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

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

Attachments:

### Replies to This Discussion

Solution 1 :

#include<iostream.h>

int max(int, int []);
int min(int, int []);
int average(int, int []);

main(){
int i=0;
int j[i+1];
int k;
while(true){
cout"Enter the number of consecutive days to read their temperature : ";
cin>>i;

for(int m=1;m<=i;m++){
cout"\nEnter temperature for day "m":";
cin>>j[m];

cout"\nThe average temperature is: "average(i, j);
cout"\nThe highest temperature is: "max(i, j);
cout"\nThe lowest temperature is: "min(i, j);

cout"\n\nPress any key for run again and press '0' for quit\n";
cin>>k;
if(k==0){
cout"\n\t\t**************************************\n";
cout"\t\tPrepared by: vustudents.ning.com \n\t\ (000000000000)";
cout"\n\t\t**************************************\n\n";
system("pause");
break;}
}
}

int max(int i, int j[]){
int l=j[1];
for(int m=1; m<=i; m++)
if(j[m]>l)
l=j[m];
return l;
}

int min(int i, int j[]){
int l=j[1];
for(int m=1; m<=i; m++)
if(j[m]<l)
l=j[m];
return l;
}

int average(int i, int j[]){
int l=0;
for(int m=1; m<=i; m++)
l=l+j[m];
l=l/i;
return l;
}

Solution 2:

#include <cstdlib>

#include <iostream>

//Decleare three function

//1) high_Temp with two parameter which get higest temprature from array
double high_Temp(double [],int);

//1) low_Temp with one parameter which get lowest temprature from array
double low_Temp(double []);

//1) Average_Temp with two parameter which get Average temprature from all array values
double Average_Temp(double [],int);

using namespace std;

int main(int argc, char *argv[])
{

//To display message on screen

cout"\t\t***********************************"endl
"\t\t TEMPRATURE CALCULATION SYSTEM "endl
"\t\t***********************************"endlendl;

//Decleare integer variable for taking size for array from user with name of days
int days;

cout"Enter the number of consecutive days to read their temperature : ";

cin>>days;

//declare array with double datatype beacause values would be in fraction. with name temp
double temp[days];

//declear two more integer to run for loops
int i, j;

//i discuss used of this variable later in program
double t;

//run this loop for taking input from user
for(i=0;i<days;i++)
{

coutendl"Enter temperature for day "i+1" : ";

cin>>temp[i];

}

//now for getting highest temprature value and lowest temprature i sort array
// due to sorting lowest value come at 0 index of array an highest value
//come at the end array so we easily extrat the highest tempature
//and lowest temprature from array

//run two loops for sorting first one take first value
//and then 2nd one compare this value with others of array
for(i=0; i<days; i++)
{

for(j=0; j<days-1; j++)
{
// here we put if condation for checking value which take by first loop is greater than 2nd value
//if it is greater then it swaps
if (temp[j] > temp[j+1])
{
//now after condation is true then t variable take the value
//which is greater than next value of array
t = temp[j];

//here value swaps with next value of array which is less than first location of array
temp[j] = temp[j+1];

//here greater value come to nex position of array and the process is continue till the loops end.
temp[j+1] = t;

}

}

}
//here display average temprature by calling Average_temp function for getting average temprature in array
//with used of temp array, days as parameter
coutendl"The Average Temprature is : "Average_Temp(temp,days);

//here display highest temprature by calling high_temp function in array
//with used of temp array, days as parameter
coutendl"The Higest Temprature is : "high_Temp(temp,days);

//here display lowest temprature by calling low_temp function for getting lowest temprature in array
//with used of temp array as parameter
coutendl"The Lowest Temprature is : "low_Temp(temp)endl;

system("pause");

}

//here is definition of high_temp which take array and integer variable as parameter

double high_Temp(double a[],int arraysize)
{

//we know that by sorting the highest value of array come to last so we just take and put arraysize in bracket with -1
//which is a[arraysize-1] beacause we know array starts with o

//to return highest temprature
return a[arraysize-1];
}

//here is definition of low_temp which take array by parameter
double low_Temp(double a[])
{

//we know that by sorting the lowest value of array come to start or at 0 location os array
//so we just take array and decleare one varable b and store value 0
//and put variable in array for getting value at 0 location
int b=0;

//to return lowest temprature

return a;
}

//here is definition of Averqe_temp which take array and integer by parameter
double Average_Temp(double a[],int arraysize)
{

//for getting average we have to plus all values array and then divide it with size of array
//decleare variable for loop
int i;

//decleare variable for plus the value of array
double c=0;

for ( i = 0 ; i < arraysize ; i ++)
{

//here value of array are plus
c=c+a[i];
}

//here total of array value is divide with size of array
c=c/i;

//to return average temprature

return c;
}

[b]Solution3 :

Quote:#include<iostream.h>
#include<conio.h>

void GetAnnualIncome(int[],int);
void CalcIncChange(int[], double[],int);
void CalcChangePercent(int[], double[], float[], int);
void IncDecYears(double[], int);
void MaxIncDecYears(int,int);

main()
{
int anlIncm[10];
double chngInc[10];
float chngIncPer[10];

cout"\n\n .... ABC Company Income Sheet ....\n"endl;
cout"Enter Income for Past 10 Years (in Millions)\n"endl;
GetAnnualIncome(anlIncm,10);
CalcIncChange(anlIncm, chngInc, 10);
CalcChangePercent(anlIncm, chngInc,chngIncPer, 10);
IncDecYears(chngInc, 10);
coutendlendl;
system("pause");
}

void GetAnnualIncome(int inc[],int size)
{
int var;
for(int i=0;i<size;i++)
{
cout"Income for Year "2000+i" : ";
cin>>var;
if(var < 0)
{
i--;
}
else if(var >=0 )
{
inc[i] = var;
}
}
}

void CalcIncChange(int inc[], double chg[],int size)
{
cout"\n\n";

chg[0] = inc[0] -1000;
for(int i=1;i<size;i++)
{
chg[i] = inc [i] - inc[i-1];
}
for(int i=0;i<size;i++)
{
if (chg[i] >= 0)
{
cout"Income Increase in Year "2000+i" : "chg[i]"million"endl;
}
else if (chg[i] < 0)
{
cout"Income Decrease in Year "2000+i" : "chg[i]*-1"million"endl;
}
}
}
void CalcChangePercent(int inc[], double chg[], float per[], int size)
{

cout"\n\n";
per[0] = (chg[0]*100 / 1000);
for(int i=1;i<size;i++)
{
per[i] = (chg [i]*100 / inc[i-1]);
}
for(int i=0;i<size;i++)
{
if (per[i] >= 0)
{
cout"Income Increase in Year "2000+i": "per[i]"%"endl;
}
else if (per[i] < 0)
{
cout"Income Decrease in Year "2000+i": "per[i]*-1"%"endl;
}
}
}

void IncDecYears(double chg[], int size)
{
int max, min;
cout"\n\nIncome Increased in the following years: "endl;
for(int i=0;i<size;i++)
{
max=min=0;
if (chg[i] >= 0)
{

if(chg[max] < chg[i])
{
max = i;

cout2000+i", ";
}
}
cout"\n\nIncome Decreased in the following years: "endl;
for(int i=0;i<size;i++)
{
if (chg[i] < 0)
{
if(chg[min] > chg[i])
{
min = i;
}
cout2000+i", ";
}
}
MaxIncDecYears(max+2000,min+2000);

void MaxIncDecYears(int max,int min)
{
cout"\n\nYear with maximium income Increase: "maxendl;
cout"Year with maximium income Decrease: "minendl;

system("pause");
}

CS201 Introduction to Programming Solution ( due Date 02.05.2012)

Problem Statement:    Temperature Calculation system

Write a program that displays average, highest and lowest temperatures.

Detailed Description:

• The program will take temperature readings as input from user for specified number of consecutive days.
• Program will store these temperature values into an array.
• Then it will pass this array to three different functions.
• One function will return highest temperature, one will return lowest temperature and third one will return average temperature.
• All these functions will be called inside main() function where these temperature results will be displayed to the user.

Sample Output:

Enter the number of consecutive days to read their temperature : 5
Enter temperature for day 1: 50
Enter temperature for day 2: 80
Enter temperature for day 3: 30
Enter temperature for day 4: 92
Enter temperature for day 5: 47

The average temperature is 59.80
The highest temperature is 92.00
The lowest temperature is 30.00

cs201 2nd assignment solution 2012

#include<iostream.h>
#include<conio.h>

void GetAnnualIncome(int[],int);
void CalcIncChange(int[], double[],int);
void CalcChangePercent(int[], double[], float[], int);
void IncDecYears(double[], int);
void MaxIncDecYears(int,int);

main()
{
int anlIncm[10];
double chngInc[10];
float chngIncPer[10];

cout"\n\n .... ABC Company Income Sheet ....\n"endl;
cout"Enter Income for Past 10 Years (in Millions)\n"endl;
GetAnnualIncome(anlIncm,10);
CalcIncChange(anlIncm, chngInc, 10);
CalcChangePercent(anlIncm, chngInc,chngIncPer, 10);
IncDecYears(chngInc, 10);
coutendlendl;
system("pause");
}

void GetAnnualIncome(int inc[],int size)
{
int var;
for(int i=0;i<size;i++)
{
cout"Income for Year "2000+i" : ";
cin>>var;
if(var < 0)
{
i--;
}
else if(var >=0 )
{
inc[i] = var;
}
}
}
www.vustudents.ning.com

void CalcIncChange(int inc[], double chg[],int size)
{
cout"\n\n";

chg[0] = inc[0] -1000;
for(int i=1;i<size;i++)
{
chg[i] = inc [i] - inc[i-1];
}
for(int i=0;i<size;i++)
{
if (chg[i] >= 0)
{
cout"Income Increase in Year "2000+i" : "chg[i]"million"endl;
}
else if (chg[i] < 0)
{
cout"Income Decrease in Year "2000+i" : "chg[i]*-1"million"endl;
}
}
}
void CalcChangePercent(int inc[], double chg[], float per[], int size)
{

cout"\n\n";
per[0] = (chg[0]*100 / 1000);
for(int i=1;i<size;i++)
{
per[i] = (chg [i]*100 / inc[i-1]);
}
for(int i=0;i<size;i++)
{
if (per[i] >= 0)
{
cout"Income Increase in Year "2000+i": "per[i]"%"endl;
}
else if (per[i] < 0)
{
cout"Income Decrease in Year "2000+i": "per[i]*-1"%"endl;
}
}
}

www.vustudents.ning.com

void IncDecYears(double chg[], int size)
{
int max, min;
cout"\n\nIncome Increased in the following years: "endl;
for(int i=0;i<size;i++)
{
max=min=0;
if (chg[i] >= 0)
{

if(chg[max] < chg[i])
{
max = i;
}
cout2000+i", ";
}
}
cout"\n\nIncome Decreased in the following years: "endl;
for(int i=0;i<size;i++)
{
if (chg[i] < 0)
{
if(chg[min] > chg[i])
{
min = i;
}
cout2000+i", ";
}
}
MaxIncDecYears(max+2000,min+2000);

}

void MaxIncDecYears(int max,int min)
{
cout"\n\nYear with maximium income Increase: "maxendl;
cout"Year with maximium income Decrease: "minendl;

system("pause");
}

www.vustudents.ning.com

CS201+Assignment#2+Solution

Attachments:

//***************1234567890**************
//frnds plzz make some changing warnaaaaaaaaa anda to sab khaty rahty han hahaha***********
#include<iostream.h>
#include<conio.h>
float avg(int [],int);
float low(int [],int);
float high(int [],int);

int main()
{
int n;
cout"Enter the number of consecutive days to read their temperature";
cin>>n;
coutendl;

int arr[10];
float l,h,a;
for(int i=0;i<n;i++)
{
cout"Enter the temperature for day "i+1" : ";
cin>>arr[i];
coutendl;
}
coutendl;
a=avg(arr,n);
cout"The Average Temperature is "aendl;
h=high(arr,n);
cout"The Highest temperature is "hendl;
l=low(arr,n);
cout"The Lowest temperature is "l;

getch();
}

float avg(int arr[],int n)
{
float sum=0.0,a;
for(int i=0;i<n;i++)
{
sum=sum+arr[i];

}
a=sum/5.0;
return (a);
}

float low(int arr[],int n)
{
float l=100.0;
for(int i=0;i<n;i++)
{
if(arr[i]<l)
l=arr[i];
}

return (l);
}
float high(int arr[],int n)
{
float h=0.0;
for(int i=0;i<n;i++)
{
if(arr[i]>h)
h=arr[i];

}

return (h);
}

## Latest Activity

Raheela, ishrat, Naveed Ahmad and 4 more joined Virtual University of Pakistan
12 minutes ago
+ ! ! ! Anny ! ! ! + liked Zain Kazimi's discussion Self Poetry
43 minutes ago
+ ! ! ! Anny ! ! ! + liked Jabra's discussion Mere Sth Aysa howA hai ap k Sth??
43 minutes ago
46 minutes ago
46 minutes ago
46 minutes ago
46 minutes ago
+ ! ! ! Anny ! ! ! + liked + ! ! S░!░N҉░G҉░E҉░R​⭐️'s discussion BASS!!!!!!!!
46 minutes ago
Atten Lly left a comment for Muhammad nauman
1 hour ago
Atten Lly left a comment for Fatima Amjad
1 hour ago
Atten Lly left a comment for Sohaib Mughal
1 hour ago
Atten Lly left a comment for Syed Ijlal Haider
1 hour ago

1

2

3