PSCP Assignment 23chboa14
PSCP Assignment 23chboa14
1) Number of people who attended the event on the first day was x. But as days progressed,
the event gained good response and the number of people who attended the event on the
second day was twice the number of people who attended on the first day. Unfortunately,
due to heavy rains on the third day, the number of people who attended the event was
exactly half the number of people who attended on the first day. Given the total number
of people who have attended the event in the first 3 days, write a program to find the
number of people who have attended the event on day 1, day 2 and day 3.
#include <iostream>
int main(){
float a,b,c;
int a1,b1,c1;
float d;
cin>>d;
a = 2.0/7*d;
b = 4.0/7*d;
c = 1.0/7*d;
a1 = a*10;
if(a1%10>=5){
a = a1/10 + 1;
else{
a = a1/10;
}
b1 = b*10;
if(b1%10>=5){
b = b1/10 + 1;
else{
b = b1/10;
c1 = c*10;
if(c1%10>=5){
c = c1/10 + 1;
else{
c= c1/10;
cout<<"first day:"<<int(a)<<endl;
cout<<"second day:"<<int(b)<<endl;
cout<<"third day:"<<int(c)<<endl;
return 0;
}
2) A bank intends to design a program to display the change for a given amount between 1 and
100000. The available denomination are ₹ 2000, 500, 200, 100, 50, 20, 10, 5, 2 and 1.Write a
program to accept the amount from the user and display the denomination and number of
notes of each denomination for the amount in descending order of denominations. The total
number of notes used to make the change is to be as low as possible not necessarily minimum.
#include <iostream>
int main() {
int amount;
int j = amount;
return 0;
Question:
Write a program that takes get the branding expenses, travel expenses, food expenses and
logistics expenses as input from the user and calculate the total expenses for an event and
the percentage rate of each of these expenses.
Sample Input:
Enter branding expenses: 20000
Enter travel expenses: 40000
Enter food expenses: 15000
Enter logistics expenses: 25000
Output:
Total expenses : Rs.100000.00
Branding expenses percentage : 20.00%
Travel expenses percentage : 40.00%
Food expenses percentage : 15.00%
Logistics expenses percentage : 25.00%
#include <iostream>
// Question 3
int main() {
float branding_expenses, travel_expenses, food_expenses, logistics_expenses;
cout << "Branding expenses percentage : " << (branding_expenses / total_expenses) * 100 << "%"
<< endl;
cout << "Travel expenses percentage : " << (travel_expenses / total_expenses) * 100 << "%" <<
endl;
cout << "Food expenses percentage : " << (food_expenses / total_expenses) * 100 << "%" << endl;
cout << "Logistics expenses percentage : " << (logistics_expenses / total_expenses) * 100 << "%" <<
endl;
return 0;
}
The cost price, mark price (MRP) and discount (in %) is
entered through keyboard.
Sometimes seller gets profit of x % or some time loss of y %
depends on discount. Write
a program to determine whether the seller has made profit or
incurred loss. Also
determine how much profit he made or loss incurred.
#include <iostream>
int main() {
cout << "Seller has made a profit of: " << selling_price - cost_price << endl;
cout << "Seller has incurred a loss of: " << cost_price - selling_price << endl;
else
return 0;
}
Given an unsigned integer N. The task is to swap all odd bits
with adjacent even bits.
Example : 23 (00010111) should be converted to 43
(00101011).
#include <iostream>
using namespace std;
int main() {
unsigned int N;
cout << "Enter an unsigned integer: "; cin >> N;
unsigned int result = ((N & 0xAAAAAAAA) >> 1) | ((N & 0x55555555) <<
1);
cout << "Swapped bits: " << result << endl;
return 0;
}
Question:
Write a program that unsets the rightmost set bit of an integer. Note
that Set bits in a binary number is represented by 1. Example: input
12 output 8.
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter an integer: "; cin >> num;
int result = num & (num - 1);
cout << "After unsetting rightmost set bit: " << result << endl;
return 0;
}
Write C++ syntax to read a decimal integer and display its equivalent octal and
hexa
decimal number. Note that you need to write a program to convert, but ONLY
syntax for
printing.
#include <iostream>
using namespace std;
int main() {
int decimal_integer;
cout << "Enter a decimal integer: "; cin >> decimal_integer;
cout << "Octal number: " << oct << decimal_integer << endl;
cout << "Hexadecimal number: " << hex << decimal_integer << endl;
return 0;
}
Question:
It is possible to calculate easily the day of the week on which a given date falls, if one
knows the Julian day of that date. For example, January 1 is always Julian day 1, since it
is the first day of the year, whereas December 31 is day 365 in a non-leap year or day
366 in a leap year. The day of the week is calculated as follows:
Year = year in question (all four digits)
Julian_day = Julian day of date in question (1 to 366)
fours = integer portion of (year -1)/4
hundreds = integer portion of (year-1)/100
four_hundreds = integer portion of (year-1)/400
day_of_the_week = (year + Julian_day + fours – hundreds + four_hundreds ) % 7 where:
Result Means
0 Saturday
1 Sunday
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
Write a program to calculate the day of the week as described above. Verify its
correctness by testing it on the current date.
Note: Your program need to display only the number, it need not display the
corresponding day name.
#include <iostream>
using namespace std;
int main() {
int year, Julian_day, fours, hundreds, four_hundreds;
cout << "Enter year: "; cin >> year;
cout << "Enter Julian day: "; cin >> Julian_day;
fours = (year - 1) / 4;
hundreds = (year - 1) / 100;
four_hundreds = (year - 1) / 400;
int day_of_the_week = (year + Julian_day + fours - hundreds +
four_hundreds) % 7;
cout << "Day of the week: " << day_of_the_week << endl;
return 0;
}
Question:
Calculate the mass of air in an automobile tire, using the formula
PV = 0.37m( T + 460 )
Where, P = Pressure, pounds per square inch (psi)
V = Volume, cubic feet
m = mass of air, pounds
T = temperature, degrees Fahrenheit
The tire contains two cubic feet of air. Assume that the pressure is 32 psi at
room
temperature.
#include <iostream>
using namespace std;
// Question 9
int main() {
float P = 32.0, V = 2.0, T = 70.0; // Given values
float m = (P * V) / (0.37 * (T + 460));
cout << "Mass of air in the tire: " << m << " pounds" << endl;
return 0;
}
Question:
Write a program to assist in the design of hydroelectric dam. Prompt
the user for the
height of the dam and for the number of cubic meters of water that are
projected to flow
from the top to the bottom of the dam each second. Predict how many
megawatts (1 MW
= 106 watts) of power will be produced if 90% of the work done on
the water by gravity
is converted to electrical energy. Note that the mass of one cubic
meter of water is
1000kg. Use 9.80 meters/second2 as the gravitational constant g. Be
sure to use
meaningful names for both the gravitational constant and the 90%
efficiency constant.
For one run, use a height of 170m and flow of 1.30 * 10^3 m3/s. The
relevant formula (w
= work, m = mass, g = gravity, h = height) is w = mgh.
#include <iostream>
using namespace std;
// Question 10
int main() {
float height = 170.0, flow = 1.30 * 103; // Given values
float g = 9.80; // Gravitational constant
float efficiency = 0.90;
float power = (0.90 * flow * height * g) / (1000000); // Converting
to megawatts
cout << "Predicted power output: " << power << " megawatts" <<
endl;
return 0;
}
Question:
Write a program that estimates the temperature in freezer (in degree Celcius)
given the elapsed time
(hours) since a power failure. Assume this temperature (T) is given by
T = [4t2/(t+2) ]-20
Where t is the time since the power failure. Your program should prompt the
user
to enter how long it has been since the start of the power failure in whole hours
and
minutes. Note that you will need to convert the elapsed time into hours. For
example, if
the user entered 2 30 (2 hours 30 minutes), you would need to convert this to
2.5 hours.
#include <iostream>
using namespace std;
int main() {
float t_hours, T;
int hours, minutes;
cout << "Enter time since power failure in hours and minutes: "; cin
>> hours >> minutes;
t_hours = hours + (minutes / 60.0);
T = (4 * t_hours * t_hours) / (t_hours + 2) - 20;
cout << "Estimated temperature in freezer: " << T << " oC" <<
endl;
return 0;
}
Question:
Write a program that plays the game of Mad Lib. Your program
should prompt the user
to enter the following data.
• The first or last name of the instructor
• Your name
• A food
• A number between 100 and 120
• An adjective
• A color
• An animal
After the data are input, they should be substituted into the story
below and output to the
console.
------------------------------------------------------------------------------------
----------------
Dear Instructor [Instructor Name],
I am sorry that I am unable to turn in my homework at this time. First
I ate a rotten
[Food], which made me turn [Color] and extremely ill. I came down
with a fever of
[Number 100-120]. Next, my [Adjective] pet [Animal] must have
smelled the remains of
the [Food] on my homework, because he ate it. I am currently
rewriting my homework
and hope you will accept it later.
Sincerely,
[Your Name]
------------------------------------------------------------------------------------
----------------
Hint: In place of reading a name, read a character.
#include <iostream>
using namespace std;
int main() {
char instructor_name, your_name, food, adjective, color, animal;
int number;
cout << "Enter first or last name of instructor: "; cin >>
instructor_name;
cout << "Enter your name: "; cin >> your_name;
cout << "Enter a food: "; cin >> food;
cout << "Enter a number between 100 and 120: "; cin >> number;
cout << "Enter an adjective: "; cin >> adjective;
cout << "Enter a color: "; cin >> color;
cout << "Enter an animal: "; cin >> animal;
cout << endl;
cout << "Dear Instructor " << instructor_name << "," << endl;
cout << "I am sorry that I am unable to turn in my homework at
this time. First I ate a rotten " << food << ", which made me turn " <<
color << endl;
cout<<"and extremely ill. I came down with a
fever"<<number<<"Next,my"<<adjective<<"pet"<<"musut have
smelled the remains of a "<<food<<"on my homework,because he ate
it.I am currently rewriting my home work and hope you will accept it
later"<<endl<<"sincerely"<<endl<<your_name;
return 0;
}