August 07, 2014
Capture/Record webcam, desktop and audio under Ubuntu 14.04
1 comment:
Author:
tec
at
8/07/2014 06:23:00 pm
Labels:
linux webcam screencasting,
screen recording,
screencast,
ubuntu,
ubuntu 14.04,
vlc
Bash script:
fname=`date +"%d.%m.%Y_%H:%M:%S_%P"`.'_screencast.mp4' vlc --qt-minimal-view v4l2:///dev/video0 & vlc --qt-minimal-view screen:// :screen-fps=20 :screen-follow-mouse :live-caching=300 :input-slave=alsa://hw:0,0 :sout="#transcode{vcodec=h264,vb=384,fps=5,acodec=mpga}:duplicate{dst=std{mux=mp4,access=file,dst='$fname'}}" &
These set of commands start two instances of VLC.
The first command fires up a minimal view of VLC with video source "/dev/video0" (the default location of webcamera in most general cases).
The second command starts another minimal VLC instance with video from screen:// (desktop) and audio from default built-in microphone "hw:0,0". Output is encoded and saved in current directory as an mp4 file.
Recording stops when you close VLC instances.
February 09, 2014
OOMP Assignment#4
/*
Aim: Design a C++ Class "Complex" with data members for real and imaginary part. Provide
default and parametrized constructors. Write a program to perform arithmetic operations
of two complex numbers using operator overloading (using either member functions or
friend functions).
*/
#include <iostream>
#include <math.h>
using namespace std;
class Complex{
public:
int a;
int b;
Complex(){
Complex(0, 0);
}
Complex(int x, int y){
a = x;
b = y;
}
void get(){
cout << endl << "Enter real part: ";
cin >> a;
cout << endl << "Enter imaginary part: ";
cin >> b;
print();
}
void print(){
cout << endl << a << " " << (b >= 0 ? "+" : "-") << " " << abs(b) << "i";
}
Complex operator + (Complex c){
return Complex(a + c.a, b + c.b);
}
Complex operator - (Complex c){
return Complex(a - c.a, b - c.b);
}
Complex operator *(Complex c){
return Complex(a * c.a - b * c.b, a*c.b + c.a * b);
}
Complex operator /(Complex c){
return Complex((a * c.a + b * c.b)/(c.a * c.a + c.b * c.b), (b * c.a - a * c.b)/(c.a * c.a + c.b * c.b));
}
};
int main(){
int choice;
Complex c1, c2, c3;
do{
cout << endl << "-- Complex Numbers --";
cout << endl << "1. Input numbers";
cout << endl << "2. Display numbers";
cout << endl << "3. Add";
cout << endl << "4. Subtract";
cout << endl << "5. Multiply";
cout << endl << "6. Divide";
cout << endl << "7. Exit";
cout << endl << "Enter your choice: ";
cin >> choice;
switch(choice){
case 1 : c1.get(); c2.get(); break;
case 2 : c1.print(); c2.print(); break;
case 3 :
c3 = c1 + c2;
cout << endl << "Result of addition: ";
c3.print();
break;
case 4 :
c3 = c1 - c2;
cout << endl << "Result of subtraction: ";
c3.print();
break;
case 5 :
c3 = c1 * c2;
cout << endl << "Result of multiplication: ";
c3.print();
break;
case 6 :
c3 = c1 / c2;
cout << endl << "Result of division: ";
c3.print();
break;
default : cout << endl << "Invalid choice!"; break;
}
}while(choice != 7);
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 1
Enter real part: 10
Enter imaginary part: 20
10 + 20i
Enter real part: -15
Enter imaginary part: -25
-15 - 25i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 2
10 + 20i
-15 - 25i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 3
Result of addition:
-5 - 5i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 4
Result of subtraction:
25 + 45i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 5
Result of multiplication:
350 - 550i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 6
Result of division:
0 + 0i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 7
*/
Read More
Aim: Design a C++ Class "Complex" with data members for real and imaginary part. Provide
default and parametrized constructors. Write a program to perform arithmetic operations
of two complex numbers using operator overloading (using either member functions or
friend functions).
*/
#include <iostream>
#include <math.h>
using namespace std;
class Complex{
public:
int a;
int b;
Complex(){
Complex(0, 0);
}
Complex(int x, int y){
a = x;
b = y;
}
void get(){
cout << endl << "Enter real part: ";
cin >> a;
cout << endl << "Enter imaginary part: ";
cin >> b;
print();
}
void print(){
cout << endl << a << " " << (b >= 0 ? "+" : "-") << " " << abs(b) << "i";
}
Complex operator + (Complex c){
return Complex(a + c.a, b + c.b);
}
Complex operator - (Complex c){
return Complex(a - c.a, b - c.b);
}
Complex operator *(Complex c){
return Complex(a * c.a - b * c.b, a*c.b + c.a * b);
}
Complex operator /(Complex c){
return Complex((a * c.a + b * c.b)/(c.a * c.a + c.b * c.b), (b * c.a - a * c.b)/(c.a * c.a + c.b * c.b));
}
};
int main(){
int choice;
Complex c1, c2, c3;
do{
cout << endl << "-- Complex Numbers --";
cout << endl << "1. Input numbers";
cout << endl << "2. Display numbers";
cout << endl << "3. Add";
cout << endl << "4. Subtract";
cout << endl << "5. Multiply";
cout << endl << "6. Divide";
cout << endl << "7. Exit";
cout << endl << "Enter your choice: ";
cin >> choice;
switch(choice){
case 1 : c1.get(); c2.get(); break;
case 2 : c1.print(); c2.print(); break;
case 3 :
c3 = c1 + c2;
cout << endl << "Result of addition: ";
c3.print();
break;
case 4 :
c3 = c1 - c2;
cout << endl << "Result of subtraction: ";
c3.print();
break;
case 5 :
c3 = c1 * c2;
cout << endl << "Result of multiplication: ";
c3.print();
break;
case 6 :
c3 = c1 / c2;
cout << endl << "Result of division: ";
c3.print();
break;
default : cout << endl << "Invalid choice!"; break;
}
}while(choice != 7);
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 1
Enter real part: 10
Enter imaginary part: 20
10 + 20i
Enter real part: -15
Enter imaginary part: -25
-15 - 25i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 2
10 + 20i
-15 - 25i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 3
Result of addition:
-5 - 5i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 4
Result of subtraction:
25 + 45i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 5
Result of multiplication:
350 - 550i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 6
Result of division:
0 + 0i
-- Complex Numbers --
1. Input numbers
2. Display numbers
3. Add
4. Subtract
5. Multiply
6. Divide
7. Exit
Enter your choice: 7
*/
OOMP Assignment#3
/*
Aim: Develop an object oriented program in C++ to create a database of the personnel
information system containing the following information: Name, Date of Birth, Blood
group, Height, Weight, Insurance Policy, number, Contact address, telephone number,
driving license no. etc Construct the database with suitable member functions for
initializing and destroying the data viz constructor, default constructor, copy, constructor,
destructor, static member functions, friend class, this pointer, inline code and dynamic
memory allocation operators-new and delete.
*/
#include <iostream>
#define MAX_RECORDS 50
using namespace std;
class Information{
friend class Records;
private:
string name, dateOfBirth, bloodGroup, contactAddress;
float height, weight;
double policyNumber, telephoneNumber, licenseNumber;
public:
Information(string n, string dob, string bg, string ca, int h, int w, double pn, double tn, double ln){
this->name = string(n);
this->dateOfBirth = string(dob);
this->bloodGroup = string(bg);
this->contactAddress = string(ca);
this->height = h;
this->weight = w;
this->policyNumber = pn;
this->telephoneNumber = tn;
this->licenseNumber = ln;
}
Information(){
Information("", "", "", "", 0, 0, 0, 0, 0);
}
Information(const Information& otherInfo){
this->name = otherInfo.name;
this->dateOfBirth = otherInfo.dateOfBirth;
this->bloodGroup = otherInfo.bloodGroup;
this->contactAddress = otherInfo.contactAddress;
this->height = otherInfo.height;
this->weight = otherInfo.weight;
this->policyNumber = otherInfo.policyNumber;
this->telephoneNumber = otherInfo.telephoneNumber;
this->licenseNumber = otherInfo.licenseNumber;
}
inline void acceptValues(){
cout << endl << "Enter personal details: ";
cout << endl << "Name: ";
cin >> this->name;
cout << endl << "Date Of Birth: ";
cin >> this->dateOfBirth;
cout << endl << "Blood Group: ";
cin >> this->bloodGroup;
cout << endl << "Contact Address: ";
cin >> this->contactAddress;
cout << endl << "Height: ";
cin >> this->height;
cout << endl << "Weight: ";
cin >> this->weight;
cout << endl << "Policy Number: ";
cin >> this->policyNumber;
cout << endl << "Telephone Number: ";
cin >> this->telephoneNumber;
cout << endl << "License Number: ";
cin >> this->licenseNumber;
}
inline void display(){
cout << endl << "Personal details: " << endl;
cout << endl << "Name: " << this->name;
cout << endl << "Date Of Birth: " << this->dateOfBirth;
cout << endl << "Blood Group: " << this->bloodGroup;
cout << endl << "Contact Address: " << this->contactAddress;
cout << endl << "Height: " << this->height;
cout << endl << "Weight: " << this->weight;
cout << endl << "Policy Number: " << this->policyNumber;
cout << endl << "Telephone Number: " << this->telephoneNumber;
cout << endl << "License Number: " << this->licenseNumber << endl;
}
};
class Records{
private:
Information * records[MAX_RECORDS];
public:
static int COUNT;
static int getCount(){
return COUNT;
}
static void incCount(){
COUNT++;
}
void add(){
records[Records::getCount()] = new Information();
records[Records::getCount()]->acceptValues();
Records::incCount();
}
void display(){
for(int i = 0; i < Records::getCount(); i++){
records[i]->display();
}
}
~Records(){
for(int i = 0; i < Records::getCount(); i++){
delete records[i];
}
}
};
int Records::COUNT = 0;
int main(){
int choice;
Records * rs = new Records();
do{
cout << endl << "-- Personal Information --";
cout << endl << "1. Add information";
cout << endl << "2. Display information";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : rs->add(); break;
case 2 : rs->display(); break;
}
}while(choice != 3);
delete rs;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1
Enter personal details:
Name: Man
Date Of Birth: 4/4/1994
Blood Group: O+
Contact Address: Pune
Height: 160
Weight: 65
Policy Number: 7766554433
Telephone Number: 9988776655
License Number: 123456890
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1
Enter personal details:
Name: Tau
Date Of Birth: 5/5/1995
Blood Group: AB-
Contact Address: Mumbai
Height: 160
Weight: 45
Policy Number: 1234554321
Telephone Number: 9988006677
License Number: 0987654321
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 2
Personal details:
Name: Man
Date Of Birth: 4/4/1994
Blood Group: O+
Contact Address: Pune
Height: 160
Weight: 65
Policy Number: 7.76655e+009
Telephone Number: 9.98878e+009
License Number: 1.23457e+008
Personal details:
Name: Tau
Date Of Birth: 5/5/1995
Blood Group: AB-
Contact Address: Mumbai
Height: 160
Weight: 45
Policy Number: 1.23455e+009
Telephone Number: 9.98801e+009
License Number: 9.87654e+008
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 3
*/
Read More
Aim: Develop an object oriented program in C++ to create a database of the personnel
information system containing the following information: Name, Date of Birth, Blood
group, Height, Weight, Insurance Policy, number, Contact address, telephone number,
driving license no. etc Construct the database with suitable member functions for
initializing and destroying the data viz constructor, default constructor, copy, constructor,
destructor, static member functions, friend class, this pointer, inline code and dynamic
memory allocation operators-new and delete.
*/
#include <iostream>
#define MAX_RECORDS 50
using namespace std;
class Information{
friend class Records;
private:
string name, dateOfBirth, bloodGroup, contactAddress;
float height, weight;
double policyNumber, telephoneNumber, licenseNumber;
public:
Information(string n, string dob, string bg, string ca, int h, int w, double pn, double tn, double ln){
this->name = string(n);
this->dateOfBirth = string(dob);
this->bloodGroup = string(bg);
this->contactAddress = string(ca);
this->height = h;
this->weight = w;
this->policyNumber = pn;
this->telephoneNumber = tn;
this->licenseNumber = ln;
}
Information(){
Information("", "", "", "", 0, 0, 0, 0, 0);
}
Information(const Information& otherInfo){
this->name = otherInfo.name;
this->dateOfBirth = otherInfo.dateOfBirth;
this->bloodGroup = otherInfo.bloodGroup;
this->contactAddress = otherInfo.contactAddress;
this->height = otherInfo.height;
this->weight = otherInfo.weight;
this->policyNumber = otherInfo.policyNumber;
this->telephoneNumber = otherInfo.telephoneNumber;
this->licenseNumber = otherInfo.licenseNumber;
}
inline void acceptValues(){
cout << endl << "Enter personal details: ";
cout << endl << "Name: ";
cin >> this->name;
cout << endl << "Date Of Birth: ";
cin >> this->dateOfBirth;
cout << endl << "Blood Group: ";
cin >> this->bloodGroup;
cout << endl << "Contact Address: ";
cin >> this->contactAddress;
cout << endl << "Height: ";
cin >> this->height;
cout << endl << "Weight: ";
cin >> this->weight;
cout << endl << "Policy Number: ";
cin >> this->policyNumber;
cout << endl << "Telephone Number: ";
cin >> this->telephoneNumber;
cout << endl << "License Number: ";
cin >> this->licenseNumber;
}
inline void display(){
cout << endl << "Personal details: " << endl;
cout << endl << "Name: " << this->name;
cout << endl << "Date Of Birth: " << this->dateOfBirth;
cout << endl << "Blood Group: " << this->bloodGroup;
cout << endl << "Contact Address: " << this->contactAddress;
cout << endl << "Height: " << this->height;
cout << endl << "Weight: " << this->weight;
cout << endl << "Policy Number: " << this->policyNumber;
cout << endl << "Telephone Number: " << this->telephoneNumber;
cout << endl << "License Number: " << this->licenseNumber << endl;
}
};
class Records{
private:
Information * records[MAX_RECORDS];
public:
static int COUNT;
static int getCount(){
return COUNT;
}
static void incCount(){
COUNT++;
}
void add(){
records[Records::getCount()] = new Information();
records[Records::getCount()]->acceptValues();
Records::incCount();
}
void display(){
for(int i = 0; i < Records::getCount(); i++){
records[i]->display();
}
}
~Records(){
for(int i = 0; i < Records::getCount(); i++){
delete records[i];
}
}
};
int Records::COUNT = 0;
int main(){
int choice;
Records * rs = new Records();
do{
cout << endl << "-- Personal Information --";
cout << endl << "1. Add information";
cout << endl << "2. Display information";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : rs->add(); break;
case 2 : rs->display(); break;
}
}while(choice != 3);
delete rs;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1
Enter personal details:
Name: Man
Date Of Birth: 4/4/1994
Blood Group: O+
Contact Address: Pune
Height: 160
Weight: 65
Policy Number: 7766554433
Telephone Number: 9988776655
License Number: 123456890
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 1
Enter personal details:
Name: Tau
Date Of Birth: 5/5/1995
Blood Group: AB-
Contact Address: Mumbai
Height: 160
Weight: 45
Policy Number: 1234554321
Telephone Number: 9988006677
License Number: 0987654321
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 2
Personal details:
Name: Man
Date Of Birth: 4/4/1994
Blood Group: O+
Contact Address: Pune
Height: 160
Weight: 65
Policy Number: 7.76655e+009
Telephone Number: 9.98878e+009
License Number: 1.23457e+008
Personal details:
Name: Tau
Date Of Birth: 5/5/1995
Blood Group: AB-
Contact Address: Mumbai
Height: 160
Weight: 45
Policy Number: 1.23455e+009
Telephone Number: 9.98801e+009
License Number: 9.87654e+008
-- Personal Information --
1. Add information
2. Display information
3. Exit
Your choice: 3
*/
OOMP Assignment#2
/*
Aim: A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a
customer wants a book, the sales person inputs the title and author and the system
searches the list and displays whether it is available or not. If it is not, an appropriate
message is displayed. If it is, then the system displays the book details and requests
for the number of copies required. If the requested copies book details and requests
for the number of copies required. If the requested copies are available, the total cost
of the requested copies is displayed; otherwise the message "Required copies not in
stock" is displayed. Design a system using a class called books with suitable member functions and
Constructors. Use new operator in constructors to allocate memory space required.
Implement C++ program for the system.
*/
#include <iostream>
#include <string.h>
#define MAX_BOOKS 50
using namespace std;
class Book{
friend class BookShop;
string author;
string title;
string publisher;
int stockPosition;
float price;
public:
Book(){
author = "";
title = "";
publisher = "";
stockPosition = 0;
price = 0;
}
float getPrice(int numOrder){
return price * numOrder;
}
bool isAvailable(int numOrder){
return numOrder <= stockPosition;
}
void printDetails(){
cout << endl << "--- Book details ---";
cout << endl << "Title: " << title;
cout << endl << "Author: " << author;
cout << endl << "Publisher: " << publisher;
cout << endl << "StockPosition: " << stockPosition;
cout << endl << "Price: Rs." << price;
}
void get(){
cout << endl << "Enter new book details: ";
cout << endl << "Title: ";
cin >> title;
cout << endl << "Author: ";
cin >> author;
cout << endl << "Publisher: ";
cin >> publisher;
cout << endl << "Price: ";
cin >> price;
cout << endl << "Stock Position: ";
cin >> stockPosition;
}
void placeOrder(){
int numOrder;
cout << endl << "Enter number of copies: ";
cin >> numOrder;
if(isAvailable(numOrder)){
cout << endl << "Required copies are available in stock. Total price: Rs." << getPrice(numOrder);
}else{
cout << endl << "Required copies not in stock.";
}
}
};
class BookShop{
Book * books[MAX_BOOKS];
int index;
public:
BookShop(){
index = 0;
}
void add(){
books[index] = new Book();
books[index]->get();
index++;
}
void request(){
int choice = 0, search = -1;
cout << endl << "Search for book by: ";
cout << endl << "1) Title";
cout << endl << "2) Author";
cout << endl << "Enter choice: ";
cin >> choice;
switch(choice){
case 1 : search = searchTitle(); break;
case 2 : search = searchAuthor(); break;
default: cout << endl << "Invalid choice!"; break;
}
if(search == -1){
cout << endl << "No results found!";
}else{
cout << endl << "Book found: ";
books[search]->printDetails();
books[search]->placeOrder();
}
}
int searchTitle(){
string title;
cout << endl << "Enter book title to search: ";
cin >> title;
for(int i = 0; i < index; i++){
if(title.compare(books[i]->title) == 0){
return i;
}
}
return -1;
}
int searchAuthor(){
string author;
cout << endl << "Enter author name to search: ";
cin >> author;
for(int i = 0; i < index; i++){
if(author.compare(books[i]->author) == 0){
return i;
}
}
return -1;
}
};
int main(){
int choice;
BookShop * bs = new BookShop();
do{
cout << endl << "-- Book Shop --";
cout << endl << "1. Add book";
cout << endl << "2. Request book";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : bs->add(); break;
case 2 : bs->request(); break;
}
}while(choice != 3);
delete bs;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 1
Enter new book details:
Title: Gravity
Author: Rohit
Publisher: GHRCEM
Price: 400
Stock Position: 10
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 1
Enter new book details:
Title: Inferno
Author: Tauseef
Publisher: GHRCEM
Price: 350
Stock Position: 5
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 2
Search for book by:
1) Title
2) Author
Enter choice: 1
Enter book title to search: Gravity
Book found:
--- Book details ---
Title: Gravity
Author: Rohit
Publisher: GHRCEM
StockPosition: 10
Price: Rs.400
Enter number of copies: 15
Required copies not in stock.
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 2
Search for book by:
1) Title
2) Author
Enter choice: 2
Enter author name to search: Tauseef
Book found:
--- Book details ---
Title: Inferno
Author: Tauseef
Publisher: GHRCEM
StockPosition: 5
Price: Rs.350
Enter number of copies: 4
Required copies are available in stock. Total price: Rs.1400
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 3
*/
Read More
Aim: A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a
customer wants a book, the sales person inputs the title and author and the system
searches the list and displays whether it is available or not. If it is not, an appropriate
message is displayed. If it is, then the system displays the book details and requests
for the number of copies required. If the requested copies book details and requests
for the number of copies required. If the requested copies are available, the total cost
of the requested copies is displayed; otherwise the message "Required copies not in
stock" is displayed. Design a system using a class called books with suitable member functions and
Constructors. Use new operator in constructors to allocate memory space required.
Implement C++ program for the system.
*/
#include <iostream>
#include <string.h>
#define MAX_BOOKS 50
using namespace std;
class Book{
friend class BookShop;
string author;
string title;
string publisher;
int stockPosition;
float price;
public:
Book(){
author = "";
title = "";
publisher = "";
stockPosition = 0;
price = 0;
}
float getPrice(int numOrder){
return price * numOrder;
}
bool isAvailable(int numOrder){
return numOrder <= stockPosition;
}
void printDetails(){
cout << endl << "--- Book details ---";
cout << endl << "Title: " << title;
cout << endl << "Author: " << author;
cout << endl << "Publisher: " << publisher;
cout << endl << "StockPosition: " << stockPosition;
cout << endl << "Price: Rs." << price;
}
void get(){
cout << endl << "Enter new book details: ";
cout << endl << "Title: ";
cin >> title;
cout << endl << "Author: ";
cin >> author;
cout << endl << "Publisher: ";
cin >> publisher;
cout << endl << "Price: ";
cin >> price;
cout << endl << "Stock Position: ";
cin >> stockPosition;
}
void placeOrder(){
int numOrder;
cout << endl << "Enter number of copies: ";
cin >> numOrder;
if(isAvailable(numOrder)){
cout << endl << "Required copies are available in stock. Total price: Rs." << getPrice(numOrder);
}else{
cout << endl << "Required copies not in stock.";
}
}
};
class BookShop{
Book * books[MAX_BOOKS];
int index;
public:
BookShop(){
index = 0;
}
void add(){
books[index] = new Book();
books[index]->get();
index++;
}
void request(){
int choice = 0, search = -1;
cout << endl << "Search for book by: ";
cout << endl << "1) Title";
cout << endl << "2) Author";
cout << endl << "Enter choice: ";
cin >> choice;
switch(choice){
case 1 : search = searchTitle(); break;
case 2 : search = searchAuthor(); break;
default: cout << endl << "Invalid choice!"; break;
}
if(search == -1){
cout << endl << "No results found!";
}else{
cout << endl << "Book found: ";
books[search]->printDetails();
books[search]->placeOrder();
}
}
int searchTitle(){
string title;
cout << endl << "Enter book title to search: ";
cin >> title;
for(int i = 0; i < index; i++){
if(title.compare(books[i]->title) == 0){
return i;
}
}
return -1;
}
int searchAuthor(){
string author;
cout << endl << "Enter author name to search: ";
cin >> author;
for(int i = 0; i < index; i++){
if(author.compare(books[i]->author) == 0){
return i;
}
}
return -1;
}
};
int main(){
int choice;
BookShop * bs = new BookShop();
do{
cout << endl << "-- Book Shop --";
cout << endl << "1. Add book";
cout << endl << "2. Request book";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : bs->add(); break;
case 2 : bs->request(); break;
}
}while(choice != 3);
delete bs;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 1
Enter new book details:
Title: Gravity
Author: Rohit
Publisher: GHRCEM
Price: 400
Stock Position: 10
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 1
Enter new book details:
Title: Inferno
Author: Tauseef
Publisher: GHRCEM
Price: 350
Stock Position: 5
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 2
Search for book by:
1) Title
2) Author
Enter choice: 1
Enter book title to search: Gravity
Book found:
--- Book details ---
Title: Gravity
Author: Rohit
Publisher: GHRCEM
StockPosition: 10
Price: Rs.400
Enter number of copies: 15
Required copies not in stock.
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 2
Search for book by:
1) Title
2) Author
Enter choice: 2
Enter author name to search: Tauseef
Book found:
--- Book details ---
Title: Inferno
Author: Tauseef
Publisher: GHRCEM
StockPosition: 5
Price: Rs.350
Enter number of copies: 4
Required copies are available in stock. Total price: Rs.1400
-- Book Shop --
1. Add book
2. Request book
3. Exit
Your choice: 3
*/
January 28, 2014
OOMP Assignment#1
/*
Aim: Create a class named weather report that holds a daily weather report with datamembers day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The
constructor initializes the fields with default values: 99 for day_of_month, 999 for
hightemp,-999 for low emp and 0 for amount_rain and amount_snow. Include a
function that prompts the user and sets values for each field so that you can override
the default values. Write a C++/Java/Python program that creates a monthly report.
*/
#include <iostream>
#include <cmath>
#define MAX_MONTH 12
#define MAX_DAY 30
using namespace std;
class WeatherReport{
public:
int day_of_month, high_temp, low_temp, amount_snow, amount_rain;
WeatherReport(){
day_of_month = 99;
high_temp = 999;
low_temp = -999;
amount_snow = amount_rain = 0;
}
void get(){
cout << endl << "Enter day of month: ";
cin >> day_of_month;
cout << endl << "Enter high temperature: ";
cin >> high_temp;
cout << endl << "Enter low temperature: ";
cin >> low_temp;
cout << endl << "Enter amount of rain: ";
cin >> amount_rain;
cout << endl << "Enter amount of snow: ";
cin >> amount_snow;
}
int format(int number, int digit = 3){
int base = (int) (pow(10.0, digit-1) + 0.5f);
cout << ((number < 0) ? "-" : "+");
number = abs(number);
while(number < base && base > 1){
cout << "0";
base /= 10;
}
return number;
}
void display(){
cout << endl;
cout << format(day_of_month) << "\t";
cout << format(high_temp) << "\t";
cout << format(low_temp) << "\t";
cout << format(amount_rain) << "\t";
cout << format(amount_snow);
}
};
class YearReport{
WeatherReport * wr[MAX_MONTH][MAX_DAY];
int month, day;
public:
YearReport(){
month = day = 0;
for(int i = 0; i < MAX_MONTH; i++){
for(int j = 0; j < MAX_DAY; j++){
wr[i][j] = new WeatherReport();
}
}
}
void getMonth(){
cout << endl << "Enter month: ";
cin >> month;
if(month <= 0 || month > MAX_MONTH){
month = 0;
cout << endl << "Month must be in the range 1 - " << MAX_MONTH;
}
}
void getDay(){
cout << endl << "Enter day: ";
cin >> day;
if(day <= 0 || day > MAX_DAY){
day = 0;
cout << endl << "Day must be in the range 1 - " << MAX_DAY;
}
}
void get(){
getMonth();
getDay();
if(month > 0 && day > 0){
wr[month-1][day-1]->get();
}
}
void display(){
getMonth();
cout << endl << "Day Temp_H Temp_L Rain Snow";
cout << endl << "-------------------------------------";
if(month > 0){
for(int i = 0; i < MAX_DAY; i++){
wr[month-1][i]->display();
}
}
displayAverage();
}
void displayAverage(){
if(month > 0){
float avg_ht = 0, avg_lt = 0, avg_r = 0, avg_s = 0, count = 0;
for(int i = 0; i < MAX_DAY; i++){
if(wr[month-1][i]->day_of_month != 99){
avg_ht += wr[month-1][i]->high_temp;
avg_lt += wr[month-1][i]->low_temp;
avg_s += wr[month-1][i]->amount_snow;
avg_r += wr[month-1][i]->amount_rain;
count += 1;
}
}
if(count != 0){
avg_ht /= count;
avg_lt /= count;
avg_s /= count;
avg_r /= count;
}
cout << endl << "Avg" << endl << " \t" << avg_ht << "\t" << avg_lt << "\t" << avg_r << "\t" << avg_s;
}
}
};
int main(){
int choice;
YearReport * yr = new YearReport();
do{
cout << endl << "-- Weather Report --";
cout << endl << "1. Enter data";
cout << endl << "2. Display Report";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : yr->get(); break;
case 2 : yr->display(); break;
}
}while(choice != 3);
delete yr;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 1
Enter month: 1
Enter day: 1
Enter day of month: 1
Enter high temperature: 15
Enter low temperature: -10
Enter amount of rain: 20
Enter amount of snow: 10
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 1
Enter month: 1
Enter day: 2
Enter day of month: 2
Enter high temperature: 14
Enter low temperature: -15
Enter amount of rain: 30
Enter amount of snow: 20
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 2
Enter month: 1
Day Temp_H Temp_L Rain Snow
-------------------------------------
+001 +015 -010 +020 +010
+002 +014 -015 +030 +020
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
Avg
14.5 -12.5 25 15
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 3
*/
Read More
Aim: Create a class named weather report that holds a daily weather report with datamembers day_of_month,hightemp,lowtemp,amount_rain and amount_snow. The
constructor initializes the fields with default values: 99 for day_of_month, 999 for
hightemp,-999 for low emp and 0 for amount_rain and amount_snow. Include a
function that prompts the user and sets values for each field so that you can override
the default values. Write a C++/Java/Python program that creates a monthly report.
*/
#include <iostream>
#include <cmath>
#define MAX_MONTH 12
#define MAX_DAY 30
using namespace std;
class WeatherReport{
public:
int day_of_month, high_temp, low_temp, amount_snow, amount_rain;
WeatherReport(){
day_of_month = 99;
high_temp = 999;
low_temp = -999;
amount_snow = amount_rain = 0;
}
void get(){
cout << endl << "Enter day of month: ";
cin >> day_of_month;
cout << endl << "Enter high temperature: ";
cin >> high_temp;
cout << endl << "Enter low temperature: ";
cin >> low_temp;
cout << endl << "Enter amount of rain: ";
cin >> amount_rain;
cout << endl << "Enter amount of snow: ";
cin >> amount_snow;
}
int format(int number, int digit = 3){
int base = (int) (pow(10.0, digit-1) + 0.5f);
cout << ((number < 0) ? "-" : "+");
number = abs(number);
while(number < base && base > 1){
cout << "0";
base /= 10;
}
return number;
}
void display(){
cout << endl;
cout << format(day_of_month) << "\t";
cout << format(high_temp) << "\t";
cout << format(low_temp) << "\t";
cout << format(amount_rain) << "\t";
cout << format(amount_snow);
}
};
class YearReport{
WeatherReport * wr[MAX_MONTH][MAX_DAY];
int month, day;
public:
YearReport(){
month = day = 0;
for(int i = 0; i < MAX_MONTH; i++){
for(int j = 0; j < MAX_DAY; j++){
wr[i][j] = new WeatherReport();
}
}
}
void getMonth(){
cout << endl << "Enter month: ";
cin >> month;
if(month <= 0 || month > MAX_MONTH){
month = 0;
cout << endl << "Month must be in the range 1 - " << MAX_MONTH;
}
}
void getDay(){
cout << endl << "Enter day: ";
cin >> day;
if(day <= 0 || day > MAX_DAY){
day = 0;
cout << endl << "Day must be in the range 1 - " << MAX_DAY;
}
}
void get(){
getMonth();
getDay();
if(month > 0 && day > 0){
wr[month-1][day-1]->get();
}
}
void display(){
getMonth();
cout << endl << "Day Temp_H Temp_L Rain Snow";
cout << endl << "-------------------------------------";
if(month > 0){
for(int i = 0; i < MAX_DAY; i++){
wr[month-1][i]->display();
}
}
displayAverage();
}
void displayAverage(){
if(month > 0){
float avg_ht = 0, avg_lt = 0, avg_r = 0, avg_s = 0, count = 0;
for(int i = 0; i < MAX_DAY; i++){
if(wr[month-1][i]->day_of_month != 99){
avg_ht += wr[month-1][i]->high_temp;
avg_lt += wr[month-1][i]->low_temp;
avg_s += wr[month-1][i]->amount_snow;
avg_r += wr[month-1][i]->amount_rain;
count += 1;
}
}
if(count != 0){
avg_ht /= count;
avg_lt /= count;
avg_s /= count;
avg_r /= count;
}
cout << endl << "Avg" << endl << " \t" << avg_ht << "\t" << avg_lt << "\t" << avg_r << "\t" << avg_s;
}
}
};
int main(){
int choice;
YearReport * yr = new YearReport();
do{
cout << endl << "-- Weather Report --";
cout << endl << "1. Enter data";
cout << endl << "2. Display Report";
cout << endl << "3. Exit";
cout << endl << "Your choice: ";
cin >> choice;
switch(choice){
case 1 : yr->get(); break;
case 2 : yr->display(); break;
}
}while(choice != 3);
delete yr;
return 0;
}
/*
---------------------------------------
OUTPUT
---------------------------------------
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 1
Enter month: 1
Enter day: 1
Enter day of month: 1
Enter high temperature: 15
Enter low temperature: -10
Enter amount of rain: 20
Enter amount of snow: 10
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 1
Enter month: 1
Enter day: 2
Enter day of month: 2
Enter high temperature: 14
Enter low temperature: -15
Enter amount of rain: 30
Enter amount of snow: 20
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 2
Enter month: 1
Day Temp_H Temp_L Rain Snow
-------------------------------------
+001 +015 -010 +020 +010
+002 +014 -015 +030 +020
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
+099 +999 -999 +000 +000
Avg
14.5 -12.5 25 15
-- Weather Report --
1. Enter data
2. Display Report
3. Exit
Your choice: 3
*/
Subscribe to:
Posts (Atom)