a) Write code to create ‘Shape’ class and include following:
1. A positive integer n is said to be prime (or, "a prime") if and only if n is greater than 1 and is divisible only by 1 and n. For example, the integers 17 and 29 are prime, but 1 and 38 are not prime. Write a function named "is_prime" that takes a positive integer argument and returns as its value the integer 1 if the argument is prime and returns the integer 0 otherwise. Thus, for example:
cout << is_prime(19) << endl; // will print 1
cout << is_prime(1) << endl; // will print 0
cout << is_prime(51) << endl; // will print 0
cout << is_prime(-13) << endl; // will print 0
1. Write a function named "sum_from_to" that takes two integer arguments, call them "first" and "last", and returns as its value the sum of all the integers between first and last inclusive. Thus, for example:
cout << sum_from_to(4,7) << endl; //will print 22 because 4+5+6+7 = 22
cout << sum_from_to(-3,1) << endl; //will print -5 'cause (-3)+(-2)+(-1)+0 +1 = -5
cout << sum_from_to(7,9) << endl; //will print 22 because 7+8+9 = 24
cout << sum_from_to(9,9) << endl; //will print 9
Write a program in C++ to open and read the contents of the Text1.txt using the file stream class. Close the file and again open to update the contents of given file Text1.txt. Text1.txt : I am enjoying learning OOPS concepts After update Text1.txt: I am enjoying learning OOPS concepts Now learnt C++; Java is my next target.
create a program that should ask a user input either 0 (tails) or
1 (heads). Then the program will draw a coin flip. The program will declare the
user a winner if the result of the coin flip is equal to the user input. If the
user enters a value outside the given choices, it will display invalid choice.
Explain with an example how one user defined data type can be converted to a predefined data type.
. Write a program to perform binary operator overloading for a class named "data". The details of operators to be overloaded are:
+ will subtract the numbers
- will divide the numbers
*will add the numbers
/ will multiply the numbers
Write a program to permanently store the data entered by the user. When user is done with Input, then print the confirmation message as "Content saved successfully" along with the number of character stored.
A security company/Ambulance Service/Fire Service/Police Service wishes to optimally place vehicles in an area such that the response time to any given call within the area is reached within a given time. It also wishes to find the optimal number of security patrol cars to be deployed within the given area. Use a computational geometric approach to develop a code that receives the alarm/homes points, the targeted time to reach the alarm/home and the average speed of cars within the area and identifies where the vehicles can be optimally placed and also determines the number of vehicles required. The alarm/call points (x1, y1), (x2, y2), ..., (xn, yn) are stored in vectors X = [x1, x2, ..., xn], Y = [y1, y2, ..., yn]. Clearly state your assumptions.
Write a program to implement the following operations (the ones mentioned in comments) on Matrix. The main() function of the above program is as below: