Define a class Book with data members with book id,book name,author ,quantity and price.
If the price of a book is above 500 ,customer will get a discount of 10%. Write C++ program
to prepare purchase bill of a book.
2. Examine the following program. Imagine entering three numbers, and write what output you expect
#include <iostream.h>
int main() {
int a, b, c;
cout << "Please enter three numbersin":
cout << "a:
":cout << "\nb: ";
cin >> b;
cout << "\nc: ".
cin >> c:
if (c == (a-b))
{
cout << "a: ":
cout << a;
cout << "minus b: ";
cout << b;
cout << "equals c: ";
cout <<c<< endl;
}
else
cout << "a-b does not equal c: " << endl;
}
4. Examine this program and anticipate the output:
#include <iostream.h>
int main(){
int a = 1, b = 1, c=2;
if (c = (a-b))
6: cout << "The value of c is: " << c;
}
An integer number is said to be a perfect number if the sum of its factors, including 1 (but not the number itself), is equal to the number. For example, 6 is a perfect number, because 6 = 1
+ 2 + 3. Write a function perfect that determines whether parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect.
You need to create a program that uses loops to perform an output the sum of all odd numbers between Num1 and Num2. (use loop); create a user-defined function called sum(). Declare a variable called sumodd in the main() for the sum(). sum() is a value returning function. Use sumodd to hold a returned value.
You need to create a program that uses loops to perform an output of all even numbers between Num1 and Num2. (use loop); create a user-defined function. The function is a void function.
Allow the user to input two integers. Variables: Num1 and Num2 (Num1 must be less than Num2, values must be a positive number) (use loop); create a user-defined function to validate the user's input.
Write a program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers.
You need to create a program that uses loops to perform the following steps.
1. Allow the user to input two integers. Variables: Num1 and Num2 (Num1 must be less than Num2, values must be a positive number) (use loop); create a user-defined function to validate the user's input.
2. Output all even numbers between Num1 and Num2. (use loop); create a user-defined function. The function is a void function.
3. Output the sum of all odd numbers between Num1 and Num2. (use loop); create a user-defined function called sum(). Declare a variable called sumodd in the main() for the sum(). sum() is a value returning function. Use sumodd to hold a returned value.
Assume a and b are two (20, 20) numpy arrays. The L2-distance (defined above) between two equal dimension arrays can be calculated in python as follows:
def l2_dist(a, b):
result = ((a - b) * (a - b)).sum()
result = result ** 0.5
return result
Which of the following expressions using this function will give an error?
l2_dist(np.reshape(a, (20 * 20)), np.reshape(b, (20 * 20, 1)))