0% found this document useful (0 votes)
26 views

Assignment 1_C++

The document contains four C++ programs that perform different tasks: calculating average prices of bakery items, determining salesperson earnings based on gross sales, computing electricity bills based on units consumed, and calculating the sum, average, and standard deviation of user-inputted values. Each program includes input prompts and expected outputs for given test cases. The programs demonstrate basic programming concepts such as loops, conditionals, and functions.

Uploaded by

17081 Prashant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Assignment 1_C++

The document contains four C++ programs that perform different tasks: calculating average prices of bakery items, determining salesperson earnings based on gross sales, computing electricity bills based on units consumed, and calculating the sum, average, and standard deviation of user-inputted values. Each program includes input prompts and expected outputs for given test cases. The programs demonstrate basic programming concepts such as loops, conditionals, and functions.

Uploaded by

17081 Prashant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment 1

Name: Prashant Ranpura Date:5/9/21

Program:1
#include <iostream>
using namespace std;

int main() {
int input;
cout<<"enter the price of bakery item ranging from 1-999"<<endl;
int i=0;
int sum=0;
while(i<3){
cin>>input;
if(input<0 || input>999){
cout<<"enter valid amount"<<endl;
break;
}
if(input>=1 && input<=200){
cout<<"show cakes"<<endl;
sum+=input;
}
else if(input>=200 && input<=400){
cout<<"show biscuits"<<endl;
sum+=input;
}
else if(input>=400 && input<=700){
cout<<"show miscellaneous"<<endl;
sum+=input;

}
else if(input>=700 && input<=999){
cout<<"show ice cream"<<endl;
sum+=input;
}
i++;
}
float avg=sum/3;
cout<<"average of all items price:"<<avg<<endl;
return 0;
}

Input:
Enter the price of bakery item ranging from 1-999
200 400 750
Output:
Show cakes
Show biscuits
Show ice cream
Average of all item price
450
Program: 2
#include <iostream>

#define base 200

using namespace std;

int main() {

int n;
int grosssales;
cout<<"number of salesperson in company"<<endl;
cin>>n;
int i=0;
while(i<n){
cout<<"enter each salesperson gross sales"<<endl;
cin>>grosssales;
float temp=grosssales*0.09;
float ans=temp+base;
cout<<"given salesperson earnings:"<<ans<<endl;
i++;
}

return 0;
}

Input:
Number of salesperson in company
3
Enter each salesperson gross sales
5000 4000 2500
Output:
Given salesperson earnings:650
Given salesperson earnings:560
Given salesperson earnings:425
Program:3
#include <iostream>

using namespace std;

int main() {

int units;
cout<<"enter units consumed:"<<endl;
cin>>units;
int sum=0;
float finalcharge=0;
if(units<=100){
sum+=units*1;
finalcharge=sum+(sum*0.1)+50;
}
else if(units>=100 && units<=200){
int temp=units-100;
sum+=(100+(temp*2));
finalcharge=sum+(sum*0.1)+50;
}
else if(units>200 && units<=300){
int temp=units-200;
sum+=(100+200+(temp*3));
finalcharge=sum+(sum*0.1)+50;
}
else if(units>300 && units<=500){
int temp=units-300;
sum+=(100+200+300+(temp*4));
finalcharge=sum+(sum*0.1)+50;
}
else if(units>500){
int temp=units-500;
sum+=(100+200+300+800+(temp*5));
finalcharge=sum+(sum*0.1)+50;
}

cout<<"total bill:"<<finalcharge<<"rs"<<endl;

return 0;
}
Input:
Enter the units consumed:
450

Output:
Total bill:1370rs
Program:4
#include <iostream>
#include <math.h>

using namespace std;

int main() {
int *p,arr[5];
p=&arr[0];
cout<<"enter your values"<<endl;
for(int i=0;i<5;i++){
cin>>*(p+i);
}
int sum=0;
for(int i=0;i<5;i++){
sum+=*(p+i);
}
cout<<"Sum:"<<sum<<endl;
float avg=sum/5;
cout<<"Average:"<<avg<<endl;
float sd=0;
for(int i=0;i<5;i++){
sd+=pow(*(p+i)-avg,2);
}
cout<<"standard deviation:"<<sqrt(sd/5)<<endl;
}

Input:
Enter your values
12 11 10 13 18

Output:
Sum: 64
Average: 12
Standard deviation: 2.89

You might also like