Imagine a publishing company that markets both books and audio- cassette version of its works. Create a class Publication in C++ that stores the title (a string) and price (type float) of a publication. From this class derive two classes: Book, which adds a page count and Tape, which adds playing time in minutes. These... Continue Reading →
Distance Measure
Define two classes Distance1 and Distance2 in C++. Distance1 stores distance in miles and Distance2 in kmeters & meters. Reads values of the class objects and adds one object of Distance1 with the object of Distance2 class. The display should be in the format of miles or kmeters & meters depending on the type of... Continue Reading →
Volume of box 1
Design a class named Box whose dimensions are integers and private to the class. The dimensions are labelled: length l, breadth b, and height h. The default constructor of the class should initialize l, b, h and to 0. The parameterized constructor Box(int length, int breadth, int height) should initialize Box's l, b and h... Continue Reading →
ComputerUserAccess 1
Users of the computer have profile which consists of Name, Password, and Access Rights. Access rights take on values X, R, W, and A. It is possible to have default values for Password and Access rights which are the first three letters of the Name and ALL respectively. Users can change their password and access... Continue Reading →
Class and Objects 3
Create a class Employees which have a number, rank, and salary. When an employee is first recruited then all these are given values of 0. Upon confirmation, the actual values of these are entered for the employee. At the time of promotion their rank can be incremented by 1 and an employee gets an increment... Continue Reading →
BankAccountClass 2
Define a class in C++ to represent a bank account. Include the following members: Data members: a) Name of the depositor containing charecters and space only b) Account number as of integer type of 4 digit c) Type of account as either saving or current d) Balance amount in the account positive integer Member functions:... Continue Reading →
You have been given a set of complex number. It is desired to add and substract the complex number.
Input Format First line contains one integer representing the real part of first complex number. Second line contains one integer representing the imaginary part of first complex number. Third line contains one integer representing the real part of second complex number. Fourth line contains one integer representing the imaginary part of second complex number. Constraints... Continue Reading →
Python beginner’s programs.
(Without Inputs From User) "Hello World" in python. print ("Hello World") OUTPUT Adding two numbers in python. a = 10 b = 220 c = a + b print (a, ” + “, b, ” –> “, c) OUTPUT Concatenation of Strings. a = "Bhagat" b = "Singh" c = a + b print (a, ” + “, b, ” –> “, c) OUTPUT (With Inputs From User) Adding Two Numbers in python. a = int(input(“Enter First No: “)) b = int(input(“Enter Second No: “)) c = a + b print (a, ” + “, b, ” –> “, c) OUTPUT Concatenation Of Strings. a = input(“Enter First String: “) b = input(“Enter Second String: “) c = a + b print (a, ” + “, b, ” –> “, c) OUTPUT
Write a C++ program to represent call by value.
#include<iostream> using namespace std; void change(int data); int main() { int data=3; change(data); cout<<“value “<<data<<endl; return 0; } void change(int data) { data =5; } OUTPUT
Write a C++ program to represent the function overriding using AVERAGE() function.
#include <iostream> #include <string> using namespace std; int avrg( int , int ); int avrg( int , int, int); float avrg( float, int); int avrg(char, char); int main() { int average; cin >> average; int averageI; cin >> averageI; float x; cin >>x; float y; cin >>y; float averageF = avrg(x,y); char averageC = avrg('x','y');... Continue Reading →
Write a program in C++ to read and write the values in different variables using cascading of >> and <<
#include <bits/stdc++.h> using namespace std; int main(void) { int a; float b; char c; char str[50] ; cin>>a>>b>>c>>str; cout <<“integer – “<<a<<“\n”<<“float – “<<b<<“\n”<<“character- “<<c<<“\n”<<“string- “<<str; return 0; } OUTPUT
Write a C++ program to read and write the values in different types of variables using cin and cout.
#include <iostream> using namespace std; int main() { int i; cout<< "Enter an integer value: "; cin >>i; cout<< "Number entered is"<<i; cout<< " double of the number is"<<i*2<<"\n"; return 0; } OUTPUT
Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument.
def fact(number): if number==1: return 1 else: return number*fact(number-1) n=int(input(“Enter the number:”)) print(“Factorial of the number:” ,fact(n)) OUTPUT:
Write a Python program to reverse a string.
def reverse(string): return string[::-1] s=input(“Enter the string:”) print(“Reverse of the string:” ,reverse(s)) OUTPUT
Write a Python function to multiply all the numbers in a list.
def prolist(lst): pro=1 for x in lst: pro=pro*x return pro lst1=list(map(int,input(“Enter elements of list:”).split())) print(“Product of elements:”,prolist(lst1)) OUTPUT
Write a Python function to sum all the numbers in a list.
def sumlist(lst): return sum(lst) lst1=list(map(int,input(“Enter elements of list:”).split())) print(“Sum of elements:”,sumlist(lst1)) OUTPUT
Write a Python function to find the Max of three numbers.
def max(a,b,c): if a>b and a>c: return a elif b>c: return b else: return c a,b,c=map(int,input(“Enter three numbers:”).split()) print(“Maximum of the three:”,max(a,b,c)) OUTPUT
Why Python?
The canonical, “Python is a great first language”, elicited, “Python is great last language!” -Noah Spurrier Python is an easy to learn, powerful programming language. It has an efficient high-level data structure and a simple but efficacious approach to object-oriented programming. It has an elegant syntax and dynamic typing plus an interpreted nature. All these... Continue Reading →
C++ & Object Oriented Programming
“C++: where friends have access to your private members.” — Gavin Russell Baker. C++ is an object oriented computer language created by extraordinary computer scientist Bjorne Stroustrop as part of the evolution of the C family of languages. It is a general purpose programming language and is widely used these days for competitive programming. It has... Continue Reading →