Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

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 2012 CS201: Introduction to Programming Total Marks: 20 Due Date:02/05/2012

Assignment No. 02
Semester: Spring 2012

CS201: Introduction to Programming

Total Marks: 20

 

Due Date:02/05/2012

 

Instructions:

Please read the following instructions carefully before submitting assignment. 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)

 

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files, no reward will be given in any case.

 

 

Objective:

 

The objective of this assignment is to provide hands on experience of:

 

  • Functions
  • Array Manipulation

 

 

Guidelines:

 

  • Code should be properly indented and well commented.
  • Follow C/C++ rules while writing variable names, function names etc
  • Use only dev-C++ for this assignment.
  • Use appropriate C/C++ structure i.e. if-else; switch statement etc to get inputs from user where required (Marks will be deducted if inappropriate structure will be used)..

 

 

 

 

 

 

 

 

 

Assignment  

 

 

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  

 

 

 

NOTE:

The array containing temperature values must be passed to three different functions to return average, highest and lowest temperatures. Marks will be deducted if assignment is solved with some other technique.

 

 

Views: 2776

Attachments:

Replies to This Discussion

please discus here about the solution of the assignment 

thanks regards

khalid pervez 

Please Discuss here about this assignment.Thanks 

Yesss

ya solution sahee ha ka nahee

CS201 Assignment No 2 Solution Spring 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 specifiednumber 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 lowesttemperature and third one will return average temperature.
  • All these functions will be called inside main() function where thesetemperature results will be displayed to the user.Enter the number ofconsecutive days to read their temperature : 5Enter temperature for day 1:50Enter 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

NOTE:

The array containing temperature values must be passed to three different functions to return average, highest and lowest temperatures. Marks will be deducted if assignment is solved with some other technique.

 

 

Solution:

 

#include <cstdlib>
#include <iostream>

void high_Tenp(int [],int);

void low_Tenp(int []);

void Average_Tenp(int [],int);

using namespace std;

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

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

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

cin>>n;

int x[n];

int i, j, tmp;

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

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

cin>>x[i];

}

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

for(j=0; j<n-1; j++)
{

if (x[j] > x[j+1])
{

tmp = x[j];

x[j] = x[j+1];

x[j+1] = tmp;

}

}

}

Average_Tenp(x,n);

high_Tenp(x,n);

low_Tenp(x);

system("pause");

}

void high_Tenp(int a[],int arraysize)
{
cout"The Higest Temprature is : "a[arraysize-1]endl;
}

void low_Tenp(int a[])
{
int b=0;
cout"The Lowest Temprature is : "a[b]endl;
}

void Average_Tenp(int a[],int arraysize)
{
int i;

double c=0;

for ( i = 0 ; i < arraysize ; i ++)
{
c=c+a[i];
}
c=c/i;
coutendl"The Average Temprature is : "cendl;
}

void swap(int *x, int *y) //function using pointers to interchange the values

{

int tmp;

if(*x > *y)

{

tmp = *x;

*x = *y;

*y = tmp;

}

}

CS201+Assignment+No#2+Solution+Spring+2012

See the attached file please

Attachments:
CS201 Assignment No 2 Solution Spring 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 specifiednumber 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 lowesttemperature and third one will return average temperature.
All these functions will be called inside main() function where thesetemperature results will be displayed to the user.Enter the number ofconsecutive days to read their temperature : 5Enter temperature for 

day 1:50Enter 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
NOTE:

The array containing temperature values must be passed to three different functions to return average, highest and lowest temperatures. Marks will be deducted if assignment is solved with some other technique.


Solution:

#include <cstdlib>
#include <iostream>
void high_Tenp(int [],int);
void low_Tenp(int []);
void Average_Tenp(int [],int);
using namespace std;
int main(int argc, char *argv[])
{
cout"\t\t***********************************"endl
"\t\t TEMPRATURE CALCULATION SYSTEM "endl
"\t\t***********************************"endlendl;
int n;
cout"Enter the number of consecutive days to read theirtemperature : ";
cin>>n;
int x[n];
int i, j, tmp;
for(i=0;i<n;i++)
{
coutendl"Enter temperature for day "i+1" : ";
cin>>x[i];
}
for(i=0; i<n; i++)
{
for(j=0; j<n-1; j++)
{
if (x[j] > x[j+1])
{
tmp = x[j];
x[j] = x[j+1];
x[j+1] = tmp;
}
}
}
Average_Tenp(x,n);
high_Tenp(x,n);
low_Tenp(x);
system("pause");
}
void high_Tenp(int a[],int arraysize)
{
cout"The Higest Temprature is : "a[arraysize-1]endl;
}
void low_Tenp(int a[])
{
int b=0;
cout"The Lowest Temprature is : "a[b]endl;
}
void Average_Tenp(int a[],int arraysize)
{
int i;
double c=0;
for ( i = 0 ; i < arraysize ; i ++)
{
c=c+a[i];
}
c=c/i;
coutendl"The Average Temprature is : "cendl;
}
void swap(int *x, int *y) //function using pointers to interchange the values
{
int tmp;
if(*x > *y)
{
tmp = *x;
*x = *y;
*y = tmp;
}
}

tough assig :(

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

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");
}

Hainnnnnnnnnnnnn :O

ye kesa code ha :P

hahaha

 

void MaxIncDecYears(int,int); error 

on top of the solution they contain certain problem which dev C++ does not debug at..

 int  correct instead of int,int........according to my knowledge 

RSS

Looking For Something? Search Below

Latest Activity

saba zulfqar posted blog posts
1 hour ago
+ ¢αяєℓєѕѕ gιяℓ updated their profile
1 hour ago
saba zulfqar and Hania Khalid Shariff are now friends
4 hours ago
Mr Siren Head replied to Hania Khalid Shariff's discussion zero semester
9 hours ago
Profile Iconshahzad Hussain and Umar Farooq joined Virtual University of Pakistan
10 hours ago
Hania Khalid Shariff and Huma Ahmad are now friends
19 hours ago
Huma Ahmad liked Hania Khalid Shariff's profile
20 hours ago
BBA(6th smes) left a comment for Rimsha mujahid
21 hours ago

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

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

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