C Lab Assignment
C Lab Assignment
C Lab Assignment
Problem 1:
Problem 2:
Write a program that determines the maximum and the minimum of three
numbers.
Problem 3:
Write a program that checks the order of a medicine from a pharmacy store.
The program should read the order quantity and the medicine quantity in the
store. When the order quantity is more than the store quantity, your
program should display the message “No enough quantity”. When the order
quantity is less than the store quantity, you have to check that the order
quantity must be not more than 16 except there is more than 40 items in the
store. The messages that will be displayed in that cases are “Your order is
accepted” OR “You cannot order more than 16 item”
Sample outputs:
Problem 4:
Program: Given that an EMPLOYEE class contains following members:
data members: Employee number, Employee name, Basic, DA, IT, Net Salary
and print data members. Write a C++ program to read the data of N employee
and compute Net salary of each employee (DA=52% of Basic and Income Tax
(IT) =30% of the gross salary) .
Problem 5:
Algorithm:
1. Start
2. Create a class for employee with two count variables declaring as a static
member and employee id, name and designation as other data members.
3. Get the employee id name and designation from the user.
4. If the designation is MANAGER increment first count by 1 and if it is
ENGINEER increment second count by 1.
5. Finally display the total number of managers, engineers and employees.
6. Stop.
To write a C++ program to add two private data members using friend functions.
Lab Number:2
1. To write a C++ program to swap two private data members using friend
functions.
2. To write a C++ program to overload all relational operators to compare
US currency with Nepalese currency. Use conversion rate $1=NRs
101.36(Note: make two classes to represent each currency)
3. To write a C++ program to manipulate complex numbers using operator
overloading. (addition,subtraction,multiplication,division)
5. Create a 'STRING' class which char* and length as data member and
overloads ‘+’ ,’=’ and ‘ = = ‘ to perform respective operations. Use
constructor and destructor whenever suitable.
6. Modify above class to work with compile time memory allocation i.e. with
char [].
7. Overload >> and << operators to input and display time.
3. Modify Q.2 to add base class sales that holds an array of three
floats so that it can record the dollar sales of a particular
publication for the last three months. Include getdata() function to
get three Sales amount from the user and a putdata() function to
display sales figures. Alter the book and tape classes so they are
derived from both publication and sales. An object of class book or
tape should input and output sales data along with its other data.
4.
class Date
{
int day,month,year;
public:
Date();
~Date();
void display(); // displays the date
Date get(); // accesses the date members
void set(); // sets the date members
};
class Time
{
int hour;
int minute;
int second;
public:
Time();
~Time();
void display(); // displays the time
Time get();// accesses the time members
void set(); // sets the time members
};
5. class Inventory
{
private:
int quant; // number on hand
int reorder; // reorder quantity
double price; // price per unit
char* descrip; // description of item
public:
Inventory (int q, int r, double p, char* d)
{ // initialize data members }
~Inventory()
{ //release dynamically allocated memory}
void print();
};
//
// first derived class
//
class Auto : public Inventory
{
char * manufacturer;
public:
Auto (int q, int r, double p, char * d, char * man)
{ //initialize base and derive members }
}
~Auto()
{}
void print();
};
//
// Second derived class
//
class Transmission : public Inventory
{
char * vendor;
public:
Transmission (int q, int r, double p, char * d, char * ven)
{}
~ Transmission (){}
void print();
};
a. Write a main () function that creates an instance object of Auto called Car, which has the
following initial data: there is a quantity of five(5) on inventory, and two(2) on reorder;
the price per unit is $15,545.91, and the description is that of the car obtained from the
Toyota. Initialize the object Car, and print out all its vital facts.
b. A Transmission is purchased from Aztec Inc., and must be inventoried. There are 25 of
them, with 10 more on reorder. Their price is $1789.98. Instantiate and initialize an
object for Transmission, and provide the same information.
Student
Int rn
6.
Char name[20]
InternalExam FinalExam
Float
avgmark
Result