Showing posts sorted by relevance for query Structures. Sort by date Show all posts

Structures in C++

Data structures

   A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures are declared in C++ using the following syntax:
struct structure_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
where structure_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces { } there is a list with the data members, each one is specified with a type and a valid identifier as its name.
The first thing we have to know is that a data structure creates a new type: Once a data structure is declared, a new type with the identifier specified as structure_name is created and can be used in the rest of the program as if it was any other type. For example:
struct product {
  int weight;
  float price;
} ;

product apple;
product banana, melon;

We have first declared a structure type called product with two members: weight and price, each of a different fundamental type. We have then used this name of the structure type (product) to declare three objects of that type: apple, banana and melon as we would have done with any fundamental data type.

Once declared, product has become a new valid type name like the fundamental ones int, char or short and from that point on we are able to declare objects (variables) of this compound new type, like we have done with apple, banana and melon.
Right at the end of the struct declaration, and before the ending semicolon, we can use the optional field object_name to directly declare objects of the structure type. For example, we can also declare the structure objects apple, banana and melon at the moment we define the data structure type this way:

struct product {
  int weight;
  float price;
} apple, banana, melon;

It is important to clearly differentiate between what is the structure type name, and what is an object (variable) that has this structure type. We can instantiate many objects (i.e. variables, like apple, banana and melon) from a single structure type (product).
Once we have declared our three objects of a determined structure type (apple, banana and melon) we can operate directly with their members. To do that we use a dot (.) inserted between the object name and the member name. For example, we could operate with any of these elements as if they were standard variables of their respective types:

apple.weight
apple.price
banana.weight
banana.price
melon.weight
melon.price

Each one of these has the data type corresponding to the member they refer to: apple.weight, banana.weight and melon.weight are of type int, while apple.price, banana.price and melon.price are of type float.

Let's see a real example where you can see how a structure type can be used in the same way as fundamental types:
// example about structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int year;
} mine, yours;

void printmovie (movies_t movie);

int main ()
{
  string mystr;

  mine.title = "2001 A Space Odyssey";
  mine.year = 1968;

  cout << "Enter title: ";
  getline (cin,yours.title);
  cout << "Enter year: ";
  getline (cin,mystr);
  stringstream(mystr) >> yours.year;

  cout << "My favorite movie is:\n ";
  printmovie (mine);
  cout << "And yours is:\n ";
  printmovie (yours);
  return 0;
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}
Enter title: Alien
Enter year: 1979

My favorite movie is:
 2001 A Space Odyssey (1968)
And yours is:
 Alien (1979)

The example shows how we can use the members of an object as regular variables. For example, the member yours.year is a valid variable of type int, and mine.title is a valid variable of type string.

The objects mine and yours can also be treated as valid variables of type movies_t, for example we have passed them to the function printmovie as we would have done with regular variables. Therefore, one of the most important advantages of data structures is that we can either refer to their members individually or to the entire structure as a block with 
only one identifier.

Data structures are a feature that can be used to represent databases, especially if we consider the possibility of building arrays of them:
// array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

#define N_MOVIES 3

struct movies_t {
  string title;
  int year;
} films [N_MOVIES];

void printmovie (movies_t movie);

int main ()
{
  string mystr;
  int n;

  for (n=0; n<N_MOVIES; n++)
  {
    cout << "Enter title: ";
    getline (cin,films[n].title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> films[n].year;
  }

  cout << "\nYou have entered these movies:\n";
  for (n=0; n<N_MOVIES; n++)
    printmovie (films[n]);
  return 0;
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}

Nesting structures

Structures can also be nested so that a valid element of a structure can also be in its turn another structure.

struct movies_t {
  string title;
  int year;
};

struct friends_t {
  string name;
  string email;
  movies_t favorite_movie;
  } charlie, maria;

friends_t * pfriends = &charlie;
After the previous declaration we could use any of the following expressions:

charlie.name
maria.favorite_movie.title
charlie.favorite_movie.year
pfriends->favorite_movie.year
(where, by the way, the last two expressions refer to the same member). 
Enter title: Blade Runner
Enter year: 1982
Enter title: Matrix
Enter year: 1999
Enter title: Taxi Driver
Enter year: 1976
 
You have entered these movies:
Blade Runner (1982)
Matrix (1999)
Taxi Dr

Structure in C

Structure in C
#Structure is a user defined data type which hold or store heterogeneous data item or element in a singe variable. It is a Combination of primitive and derived data type.

Why Use Structure in C

In C language array is also a user defined data type but array hold or store only similar type of data, If we want to store different-different type of data in then we need to defined separate variable for each type of data.
Example: Suppose we want to store Student record, then we need to store....
  • Student Name
  • Roll number
  • Class
  • Address
For store Student name and Address we need character data type, for Roll number and class we need integer data type.
If we are using Array then we need to defined separate variable.

Example

char student_name[10], address[20];
int roll_no[5], class[5];
If we use Structure then we use single variable for all data.

Syntax

struct stu
{
char student_name[10];
char address[20];
int roll_no[5];
int class[5];
};
Note: Minimum size of Structure is one byte and Maximum size of Structure is sum of all members variable size.
Note: Empty Structure is not possible in C Language.

Defining a Structure

Syntax

struct tagname
{
Datatype1 member1;
Datatype2 member2;
Datatype3 member3;
...........
};
At end of the structure creation (;) must be required because it indicates that an entity is constructed.

Example

struct emp
{
int id;
char name[36];
int sal;
};
sizeof(struct emp) // --> 40 byte (2byte+36byte+2byte)

Syntax to create structure variable

struct tagname variable;

Difference Between Array and Structure

ArrayStructure
1Array is collection of homogeneous data.Structure is the collection of heterogeneous data.
2Array data are access using index.Structure elements are access using . operator.
3Array allocates static memory.Structures allocate dynamic memory.
4Array element access takes less time than structures.Structure elements takes more time than Array.

Example of Structure in C

#include<stdio.h>
#include<conio.h>

struct emp
{
int id;
char name[36];
float sal;
};

void main()
{
struct emp e;
clrscr();
printf("Enter employee Id, Name, Salary: ");
scanf("%d",&e.id);
scanf("%s",&e.name);
scanf("%f",&e.sal);

printf("Id: %d",e.id);
printf("\nName: %s",e.name);
printf("\nSalary: %f",e.sal);
getch();
}

Output

Output: Enter employee Id, Name, Salary: 5 Spidy 45000 Id : 05 Name: Spidy Salary: 45000.00

Syntax to access structure members

By using following operators we can access structure members.

Syntax

.     struct to member
-->   pointer to member
When the variable is normal type then go for struct to member operator.
When the variable is pointer type then go for pointer to member operator.

Difference Between Structure and Pointer in C

Structure in C refer to a collection of various data types for example you create a structure named "Student" which contains his name , roll no, DOB etc. Name is string, Roll no is int.
While pointer refer to address in C & symbol are used to point some particular place in C memory.

Union in C

Union

#A union is quite similar to the structures in C. It also store different data types in the same memory location. It is also a user defined data type same like structure.

union and structure are almost same

StructureUnion
struct student
{
int roll;
char name[10];
float marks;
}u;
union student
{
int roll;
char name[10];
float marks;
}u;

Defining a union

Union can be defined in same manner as structures, for defining union use union keyword where as for defining structure use struct keyword.

Syntax

union tagname
{
datatype member1;
datatype member2;
.......
.......
};

Example of Union

union emp
{
int ID;
char name[10];
double salary;
}u;

Accessing members of an union

The member of unions can be accessed in similar manner as Structure with union reference. Suppose, we you want to access name variable in above example, it can be accessed as u.name.

Advantage of union over structure

It occupies less memory because it occupies the memory of largest member only.

Disadvantage of union over structure

It can store data in one member only.

Difference between Structure and Union

StructureUnion
1For defining structure use struct keyword.For defining union we use union keyword
2Structure occupies more memory space than union.Union occupies less memory space than Structure.
3In Structure we can access all members of structure at a time.In union we can access only one member of union at a time.
4Structure allocates separate storage space for its every members.Union allocates one common storage space for its all members. Union find which member need more memory than other member, then it allocate that much space

Memory Allocation in Structure and Union

Structure allocates separate storage space for its every members. Union allocates one common storage space for its all members. Union find which member need more memory than other member, then it allocate that much space
In case of Structure

Syntax

struct emp
{
int ID;
char name[10];
double salary;
};

Example

For above structure, memory allocation like below.
int ID -- 2B
char name[10] -- 10B
double salary -- 8B 
Total memory allocation = 2+6+8 = 16 Bytes
In case of Union

Syntax

union emp
{
int ID;
char name[10];
double salary;
};
For above union, only 8 bytes of memory will be allocated because double data type will occupy maximum space of memory over other data types.
Total memory allocation = 8 Bytes

When use Structure and Union

When need to manipulate the data for all member variables then use structure. When need to manipulate only one member then use union.
Note:
  1. All the properties of the structure are same for union, except initialization process.
  2. In case of structure initialize all data members at a time because memory location are different but in case of union only one member need to be initialize.
  3. In case of union if we initializing multiple member then compiler will gives an error.

Example of Union in C

#include<stdio.h>
#include<conio.h>

union emp
{
int ID;
char name[10];
double salary;
}u; //  reference of union

void main()
{
clrscr();
printf("Enter emp Id: ");
scanf("%d",&u.ID);
printf("Enter emp Name: ");
scanf("%s",&u.name);
printf("Enter emp Salary: ");
scanf("%f",&u.salary);
printf("Emp ID: %d",u.ID);
printf("Emp Name: %s",u.name);
printf("Emp Salary: %f",u.salary);
getch();
}

Output

Output:
Emp ID: 100
Emp Name: Porter
Emp Salary: 20000

Features Of OOPS-Modularity in C++

                                          Modularity

Modularity is closely tied with encapsulation; think of modularity as a way of mapping encapsulated abstractions into real, physical modules.
The C/C++ convention is to create two files for each class: a header file (.h suffix) for the class interface, and an implementation file (.c, .cp, .cpp, .C suffix) for the code of the class.
Booch gives two goals for defining modules. Make a module cohesive (shared data structures, similar classes) with an interface that allows for minimal inter-module coupling.
Other considerations: team work, security, documentation.
Important to remember that the decisions concerning modularity are more physical issues, whereas the encapsulation of abstractions are logical issues of design.
It is possible to "over modularize". This can increase documentation costs and make it hard to find information.

Database And SQL


Data :-             Raw facts and figures which are useful to an organization. We cannot take decisions on the basis of data.
Information:- Well processed data is called information. We can take decisions on the basis of information
Field:-             Set of characters that represents specific data element.
Record:           Collection of fields is called a record. A record can have fields of different data types.
File:                 Collection of similar types of records is called a file.
Table:              Collection of rows and columns that contains useful data/information is called a table. A table generally refers to the passive entity which is kept in secondary storage device.
Relation:         Relation (collection of rows and columns) generally refers to an active entity on which we can perform various operations.
Database:       Collection of logically related data along with its description is termed as database.
Tuple:                         A row in a relation is called a tuple.
Attribute:       A column in a relation is called an attribute. It is also termed as field or data item.
Degree:           Number of attributes in a relation is called degree of a relation.
Cardinality:   Number of tuples in a relation is called cardinality of a relation.
Primary Key: Primary key is a key that can uniquely identifies the records/tuples in a relation. This key can
                         never be duplicated and NULL.
Foreign Key: Foreign Key is a key that is defined as a primary key in some other relation. This key is used to enforce referential integrity in RDBMS.
Candidate Key: Set of all attributes which can serve as a primary key in a relation.
Alternate Key: All the candidate keys other than the primary keys of a relation are alternate keys for a                                                                    relation.
DBA:              Data Base Administrator is a person (manager) that is responsible for defining the data base schema, setting security features in database, ensuring proper functioning of the data bases etc.

Relational Algebra
The relation algebra is the collection of operations on relations. Each operation takes one or more relations (tables) and produces another relation as its result. The operations defined in relational algebra are select, project, Cartesian product, union, set difference, set interception, natural join, division etc.
1.      Select operation(denoted by σ ):- select operation is used to select rows from a elation <"
Let us consider the table item
ItemNo
Item_Name
Price
I1
Milk
10
I2
Bread
15
I3
Ice Cream
25
I4
Namkeen
20
I5
Cake
10

2.      Project Operation (denoted by Ï€):- Project operation select columns from a relation.
Consider above table Item
To display item name & price of all items from Item table we can write
Ï€ Item_Name, Price (Item)


Result will be
Item_Name
Price
Milk
10
Bread
15
Ice Cream
25
Namkeen
20
Cake
10

3.      The Cartesian product operation (denoted by X ):- the Cartesian product  of relation A and B is written as A X B. The Cartesian product  yield a new relation having degree (Degree of A + Degree of B) and Cardinality (cardinality of A  X  Cardinality of B)
Consider the following table student and instructor

The Cartesian product Student X Instructor result in following relation
Adno
Stu_Name
Passed
Id
Inst_name
Subject
1023
Ajay
Y
101
Manoj
CS
1023
Ajay
Y
102
Subhash
ACC
6151
Sunil
N
101
Manoj
CS
6151
Sunil
N
102
Subhash
ACC
7575
Vinay
y
101
Manoj
CS
7575
Vinay
y
102
Subhash
ACC

4.      The Union Operation (denoted by U):- it produces a relation that contains tuples from both operand relations.
Consider the following relations science and commerce

The result of Science U Commerce will be as follows
Adno
Name
Class
2190
Amit
XII
2345
Nihan
XII
5467
ajay
XI
5423
Sanjay
XII
7665
sumit
XI

5.      The Set Difference Operation (Denoted by - ):- allows to find tuples that are in one relation but not in another relation.
Consider above relation science and commerce
The result of Science - Commerce will be as follows
Adno
Name
Class
2190
Amit
XII
5467
ajay
XI

6.      The Set Interception Operation (denoted by ∩) :-Set Interception operation finds tuples that are common to the two operand relations.
Consider above relation science and commerce
The result of Science ∩ Commerce will be as follows
Adno
Name
Class
2345
Nihan
XII

Structured Query Language
SQL is a non-procedural language that is used to create, manipulate and process the databases(relations).
Characteristics of SQL
Ø  It is very easy to learn and use.
Ø  Large volume of databases can be handled quite easily.
Ø  It is non-procedural language. It means that we do not need to specify the procedures to accomplish a task but just to give a command to perform the activity.
Ø  SQL can be linked to most of other high level languages that makes it first choice for the database programmers.
Processing Capabilities of SQL
The following are the processing capabilities of SQL
1.      Data Definition Language (DDL)
DDL contains commands that are used to create the tables, databases, indexes, views, sequences and
synonyms etc.
e.g: Create table, create view, create index, alter table etc.
2.      Data Manipulation Language (DML)
DML contains command that can be used to manipulate the data base objects and to query the databases for information retrieval.
e.g Select, Insert, Delete, Update etc.
3.      Data Control Language:
This language is used for controlling the access to the data. Various commands like GRANT, REVOKE etc are available in DCL.
4.      Transaction Control Language (TCL)
TCL include commands to control the transactions in a data base system. The commonly used commands in TCL are COMMIT, ROLLBACK etc.

Data types of SQL
Support the following data types
Data Type
Syntax
Description
Example
NUMBER
Number(n,d)
·         Used to store a numeric value in a field/column
·        Where n specifies the number of digits and d specifies the number of digits after the decimal point.
Amt Number(6,2)
CHAR
Char (size)
Used to store fixed length string of length size
Name Char(20)
VARCHAR /
VARCHAR2
varchar(size) /
varchar2(size)
Used to store variable length string up to length size
Address Varchar2(30)
DATE
DATE
Used to store Date
DOB Date
LONG
LONG
This data type is used to store variable length strings of upto 2 GB size
Accno LONG
RAW/LONG RAW

RAW(bytes)/
LONG RAW(bytes)

Used to store binary data (images/pictures/animation/clips etc.) up to the size bytes
Address Raw(500)

1&2 mark questions
Q1. Define the terms:
(i)          Database Abstraction
(ii)        Data inconsistency
(iii)      Conceptual level of database implementation/abstraction
(iv)      Primary Key
(v)        Candidate Key
(vi)      Relational Algebra
(vii)    Domain
Ans:. Define the terms:
i. Database Abstraction
Ans: Database system provides the users only that much information that is required by them, and hides certain details like, how the data is stored and maintained in database at hardware level. This concept/process is Database abstraction.
ii. Data inconsistency
Ans: When two or more entries about the same data do not agree i.e. when one of them stores the updated information and the other does not, it results in data inconsistency in the database.
iii. Conceptual level of database implementation/abstraction
Ans: It describes what data are actually stored in the database. It also describes the relationships existing among data. At this level the database is described logically in terms of simple data-structures.
iv. Primary Key
Ans : It is a key/attribute or a set of attributes that can uniquely identify tuples within the relation.
v. Candidate Key
Ans : All attributes combinations inside a relation that can serve as primary key are candidate key as they are candidates for being as a primary key or a part of it.
vi. Relational Algebra
Ans : It is the collections of rules and operations on relations(tables). The various operations are  selection, projection, Cartesian product, union, set difference and intersection, and joining of relations.
vii. Domain
Ans : it is the pool or collection of data from which the actual values appearing in a given column are drawn.

2 marks Practice questions
1.      What is relation? What is the difference between a tuple and an attribute?
2.      Define the following terminologies used in Relational Algebra:
(i)                 selection (ii) projection (iii) union (iv) Cartesian product
3.      What are DDL and DML?
4.      Differentiate between primary key and candidate key in a relation?
5.      What do you understand by the terms Cardinality and Degree of a relation in relational database?
6.      Differentiate between DDL and DML. Mention the 2 commands for each category.

Database and SQL : 6 marks questions
1.      Write SQL Command for (a) to (d) and output of (g)
TABLE : GRADUATE
S.NO
NAME
STIPEND
SUBJECT
AVERAGE
DIV
1
KARAN
400
PHYSICS
68
I
2
DIWAKAR
450
COMP  Sc
68
I
3
DIVYA
300
CHEMISTRY
62
I
4
REKHA
350
PHYSICS
63
I
5
ARJUN
500
MATHS
70
I
6
SABINA
400
CHEMISTRY
55
II
7
JOHN
250
PHYSICS
64
I
8
ROBERT
450
MATHS
68
I
9
RUBINA
500
COMP  Sc
62
I
10
VIKAS
400
MATHS
57
II

a.       List the names of those students who have obtained DIV I sorted by NAME.
b.      Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year assuming that the STIPEND is paid every month.
c.       To count the number of students who are either PHYSICS or COMPUTER SC graduates.
d.      To insert a new row in the GRADUATE table: 11,”KAJOL”, 300, “computer sc”, 75, 1
e.       Give the output of following sql statement based on table GRADUATE:
(i)          Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;
(ii)        Select SUM(STIPEND) from GRADUATE WHERE div=2;
(iii)      Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
(iv)      Select COUNT(distinct SUBJECT) from GRADUATE;
Sol :
a.       SELECT NAME from GRADUATE where DIV = ‘I’ order by NAME;
b.      SELECT NAME,STIPEND,SUBJECT, STIPEND*12 from GRADUATE;
c.       SELECT SUBJECT,COUNT(*) from GRADUATE group by SUBJECT having SUBJECT=’PHYISCS’ or SUBJECT=’COMPUTER SC’;
d.      INSERT INTO GRADUATE values(11,’KAJOL’,300,’COMPUTER SC’,75,1);
e.       (i)         63
(ii)        800
(iii)       475
(iv)       4

2.      Consider the following tables Sender and Recipient. Write SQL commands for the statements (i) to (iv) and give the outputs for SQL queries (v) to (viii).
Sender
SenderID
SenderName
SenderAddress
City
ND01
R Jain
2, ABC Appls
New Delhi
MU02
H Sinha
12 Newtown
Mumbai
MU15
S Jha
27/A, Park Street
Mumbai
ND50
T Prasad
122-K,SDA
New Delhi

Recipients
RecID
SenderID
RecName
RecAddress
recCity
KO05
ND01
R Bajpayee
5, Central Avenue
Kolkata
ND08
MU02
S Mahajan
116, A-Vihar
New Delhi
MU19
ND01
H Singh
2A, Andheri East
Mumbai
MU32
MU15
P K Swamy
B5, C S Terminals
Mumbai
ND48
ND50
S Tripathi
13, BI D Mayur Vihar
New delhi
(i)                 To display the names of all Senders from Mumbai
Ans.           SELECT sendername from Sender
where sendercity=’Mumbai’;
(ii)                To display the RecIC, Sendername, SenderAddress, RecName, RecAddress for every
Recipient.
Ans.           Select R.RecIC, S.Sendername, S.SenderAddress, R.RecName, R.RecAddress
from Sender S, Recepient R
where S.SenderID=R.SenderID ;
(iii)             To display Recipient details in ascending order of RecName
Ans.           SELECT * from Recipent ORDER By RecName;
(iv)             To display number of Recipients from each city
Ans.           SELECT COUNT( *) from Recipient
Group By RecCity;
(v)               SELECT DISTINCT SenderCity from Sender;
Ans.
SenderCity
Mumbai
New Delhi
(vi)             SELECT A.SenderName, B.RecName From Sender A, Recipient B
Where A.SenderID = B.SenderID AND B.RecCity =’Mumbai’;
Ans.           A.SenderName                      B.RecName
R Jain                                      H Singh
S Jha                                        P K Swamy
(vii)           SELECT RecName, RecAddress From Recipient
Where RecCity NOT IN (‘Mumbai’, ‘Kolkata’) ;
Ans.           RecName                    RecAddress
S Mahajan                   116, A Vihar
S Tripathi                     13, BID, Mayur Vihar
(viii)          SELECT RecID, RecName FROM Recipent
Where SenderID=’MU02’ or SenderID=’ND50’;
Ans.           RecID                         RecName
ND08              S Mahajan
ND48              STripathi

3.      Write SQL command for (a) to (f) on the basis of the table SPORTS
Table: SPORTS
Student
NO

Class
Name
Game1
Grade
Game2
Grade2

10
7
Sammer
Cricket
B
Swimming
A
11
8
Sujit
Tennis
A
Skating
C
12
7
Kamal
Swimming
B
Football
B
13
7
Venna
Tennis
C
Tennis
A
14
9
Archana
Basketball
A
Cricket
A
15
10
Arpit
Cricket
A
Atheletics
C
a.     Display the names of the students who have grade ‘C’ in either Game1 or Game2 or both.
b.    Display the number of students getting grade ‘A’ in Cricket.
c.     Display the names of the students who have same game for both Game1 and Game2.
d.    Display the games taken up by the students, whose name starts with ‘A’.
e.     Add a new column named ‘Marks’.
f.        Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’ in both Game1 and Game2.

Ans : a) SELECT Name from SPORTS where grade=’C’ or Grade2=’C’;
b) SELECT Count(*) from SPORTS where grade=’A’;
c) SELECT name from SPORTS where game1 = game2;
d) SELECT game,game2 from SPORTS where name like ‘A%’;
e) ALTER TABLE SPORTS add (marks int(4));
f) UPDATE SPORTS set marks=200 where grade=’A’;

4.      Consider the following tables Stationary and Consumer. Write SQL commands for the statement (i) to (iv) and output for SQL queries (v) to (viii):
Table: Stationary
S_ID
StationaryName
Company
Price
DP01
Dot Pen
ABC
10
PL02
Pencil
XYZ
6
ER05
Eraser
XYZ
7
PL01
Pencil
CAM
5
GP02
Gel Pen
ABC
15

Table: Consumer
C_ID
ConsumerName
Address
S_ID
01
Good Learner
Delhi
PL01
06
Write Well
Mumbai
GP02
12
Topper
Delhi
DP01
15
Write & Draw
Delhi
PL02
16
Motivation
Banglore
PL01
(i)                 To display the details of those consumers whose Address is Delhi.
(ii)               To display the details of Stationary whose Price is in the range of 8 to 15. (Both Value included)
(iii)             To display the ConsumerName, Address from Table Consumer, and Company and Price from table Stationary, with their corresponding matching S_ID.
(iv)             To increase the Price of all stationary by 2.
(v)               SELECT DISTINCT Address FROM Consumer;
(vi)              SELECT Company, MAX(Price), MIN(Price), COUNT(*) from Stationary GROUP BY Company;
(vii)            SELECT Consumer.ConsumerName, Stationary.StationaryName, Stationary.Price FROM Strionary, Consumer WHERE Consumer.S_ID=Stationary.S_ID;
(viii)         Select StationaryName, Price*3 From Stationary;

5.      Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
Table : GARMENT
GCODE
DESCRIPTION
PRICE
FCODE
READYDATE
10023
PENCIL SKIRT
1150
F03
19–DEC–08
10001
FORMAL SHIRT
1250
F01
12–JAN–08
10012
INFORMAL SHIRT
1550
F02
06–JUN–08
10024
BABY TOP
750
F03
07–APR–07
10090
TULIP SKIRT
850
F02
31–MAR–07
10019
EVENING GOWN
850
F03
06–JUN–08
10009
INFORMAL PANT
1500
F02
20–OCT–08
10007
FORMAL PANT
1350
F01
09–MAR–08
10020
FROCK
850
F04
09–SEP–07
10089
SLACKS
750
F03
20–OCT–08

Table : FABRIC
FCODE
TYPE
F04
POLYSTER
F02
COTTON
F03
SILK
F01
TERELENE

(i)                 To display GCODE and DESCRIPTION of a each dress in descending order of GCODE.
(ii)               To display the details of all the GARMENTs, which have READYDATE in between 08–DEC–07 and 16–JUN–08 (inclusive of both the dates).
(iii)             To display the average PRICE of all the GARMENTs, which are made up of FABRIC with FCODE as F03.
(iv)             To display FABRIC wise highest and lowest price of GARMENTs from DRESS table. (Display FCODE of each GARMENT along with highest and lowest price)
(v)               SELECT SUM (PRICE) FROM GARMENT WHERE FCODE= ‘F01’;
(vi)             SELECT DESCRIPTION, TYPE FROM GARMENT, FABRIC WHERE GARMENT.FCODE = FABRIC. FCODE AND GARMENT. PRICE>=1260;
(vii)           SELECT MAX (FCODE) FROM FABRIC;
(viii)         SELECT COUNT (DISTINCT PRICE) FROM FABRIC;