Take user input and insert the data at the respective position in the sorted 1) stack 2) queue and 3) linked list.(using arrays)
Weekends
Given two dates D1 and D2, write a program to count the number of Saturdays and Sundays from D1 to D2 (including D1 and D2).
The date in string format is like "8 Feb 2021".Input
The first line of input will contain date D1 in the string format.
The second line of input will contain date D2 in the string format.
Output
The output should be a single line containing two integers separated by space
Explanation
For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are
"30 Jan 2021" is a Saturday
"31 Jan 2021" is a Sunday
"6 Feb 2021" is a Saturday
"7 Feb 2021" is a Sunday
"13 Feb 2021" is a Saturday
"14 Feb 2021" is a Sunday
output
Saturday: 3
Sunday: 3
Sample Input 1
25 Jan 2021
14 Feb 2021
Sample Output 1
Saturday: 3
Sunday: 3
Sample Input 2
25 May 2019
22 Dec 2021
Sample Output 2
Saturday: 135
Sunday: 135
polinom = {}
for i in range(2):
n = int(input())
for item in range(n):
p, c = input().split(' ')
p, c = int(p), int(c)
if p in polinom:
polinom[p] += c
else:
polinom[p] = c
res = ''
if len(polinom) == 0:
pass
else:
flag = True
for p in polinom:
if polinom[p] == 0:
continue
if polinom[p] < 0:
if flag:
res += '-'
else:
res += ' - '
else:
if not flag:
res += ' + '
flag = False
if (abs(polinom[p]) == 1) and p == 0:
res += '1'
continue
if abs(polinom[p]) != 1:
res += str(abs(polinom[p]))
if p < 0:
res += 'x^({})'.format(p)
elif p == 1:
res += 'x'
elif p > 0:
res += 'x^{}'.format(p)
if len(res) == 0:
print('0')
else:
print(res)
Output:6 + 2x + 14x^2 + 6x^3
Expected output:6x^3 + 14x^2 + 2x + 6Consider the following classes: public abstract class Cat { private int age; private double weight; private double top_speed; public void run(double newSpeed) { ... } private void eat(double portionSize) { ... } // ... -> getXXX() and setXXX() methods here } } public class Cheetah extends Cat { private String type; public Cheetah(int age, double wt, double sp, String type) { this.type = type; setAge(age); setWeight(wt); setTopSpeed(sp); } private void run(double newSpeed) { ... } public void camouflage() { ... } // ... -> // getXXX() // and setXXX() methods here } } Which design principles are violated by these classes? Explain it and then correct it
Cake Ordering System
1) Add a new order
Let user add a new cake order into the system.
System will store the following cake information into a binary heap.
Cake information contain:
a) Order ID (auto-generated)
b) Expected delivery data and time
c) Name of the cake (e.g., butter cake, biscuit cake and etc.
d) Weight (in kg)
e) Price
f) Status (set to “new” when a new order is created)
2) Retrieve an order
System shall retrieve and remove the order (with the nearest delivery data and time) from the binary heap data structure and update the status as “in progress” and move the order into a queue data structure.
Can we not use an object of the Parent Class in the Child Class and use all its features?
consider two classes to store the names of people.class NAME will store the name in upper case and class name will store in lower case. write a program to convert the uppercase name to a lowercase name using the both at source and destination method
Q2
Consider the following classes:
public abstract class Cat {
private int age;
private double weight;
private double top_speed;
public void run(double newSpeed) { ... }
private void eat(double portionSize) { ... }
// ... -> getXXX() and setXXX() methods here }
}
public class Cheetah extends Cat {
private String type;
public Cheetah(int age, double wt, double sp, String type) {
this.type = type;
setAge(age);
setWeight(wt);
setTopSpeed(sp);
}
private void run(double newSpeed) { ... }
public void camouflage() { ... } // ... ->
//
getXXX()
//
and setXXX() methods here }
}
Which design principles are violated by these classes? Explain it and then correct it
Consider the following classes:
public abstract class Cat {
private int age; private double weight; private double top_speed;
public void run(double newSpeed) { ... }
private void eat(double portionSize) { ... }
// ... -> getXXX() and setXXX() methods here }
}
public class Cheetah extends Cat {
}
private String type;
public Cheetah(int age, double wt, double sp, String type) { this.type = type; setAge(age); setWeight(wt); setTopSpeed(sp);
} private void run(double newSpeed) { ... }
public void camouflage() { ... } // ... ->
// getXXX()
// and setXXX() methods here }
Which design principles are violated by these classes? Explain it and then correct it
write a program and input two integers in main and pass them to default constructor of the class show the result of the addition of two numbers