Vous êtes sur la page 1sur 5

1)# include<iostream>

#include<string>
using namespace std;
class Register
{
public:
string name[5];
int i;
Register()
{
cout<<"\n enter the name of the candidate";
for(i=0;i<5;i++)
{
cout<<"\n enter candidate"<<i+1;
cin>>name[i];
}
}
void candidates()
{
int j;
for(j=0;j<5;j++)
{
cout<<"\n"<<j+1<<"."<<name[j];
}
}
};
class Voting:public Register
{
public:
int id;
int a;
int cnt[5];
float p[5];
int tot;
string winner;
Voting()
{
cout<<"\n List of candidates";
candidates();
}
void casting()
{
a=1;
cnt[0]=0;
cnt[1]=0;
cnt[2]=0;
cnt[3]=0;
cnt[4]=0;
while(a!=0)

{
cout<<"\n Enter the id of the candidte to whom you want to vote";
cin>>id;
switch (id)
{
case 1: cnt[0]++;
break;
case 2: cnt[1]++;
break;
case 3: cnt[2]++;
break;
case 4: cnt[3]++;
break;
case 5: cnt[4]++;
break;
}
cout<<"\n"<<"continue? [Y:1/N:0]";
cin>>a;
}
}

void result()
{
tot=0;
int max;
int po;
for(int i=0;i<5;i++)
{
tot=tot+cnt[i];
}
for(int i=0;i<5;i++)
{
p[i]=(float(cnt[i])/tot)*100;
}
max = cnt[0];
for (int i = 1; i < 5; i++)
{
if (cnt[i] > max)
{
max = cnt[i];
po = i;
}
}
winner=name[po-1];
}

void resultannounce()
{
cout<<"\n candidates"<<"\t Votes Received"<<"\t Percentage";
for(int i=0;i<5;i++)
{
cout<<"\n"<< name[i]<<"\t"<<cnt[i]<<"\t"<<p[i]<<"%";
}
cout<<"\n"<<"Total no of votes:"<<tot;
cout<<"\n"<<"The winner is "<<winner;
}
};
int main()
{
Voting v;
v.casting();
v.result();
v.resultannounce();
return 0;
}
2) FACULTY fid , name , qualification
create table faculty (fid number(5),name char(5),qualification char(5),primary
key(fid));

BATCH bid , start_date , end_date , fid , cid , timing


create table batch(bid number(5),s_d char(10),e_d char(10),fid number(5),cid number(5),timing
char(5),foreign key(fid),foreign key(cid));
COURSE cid , cname , duration , fee
create table course(cid number(5),cname char(5),duration number(5),fee number(5),
foreign key(cid));
STUDENT sid , sname , gender , doj , bid , cid
create table student (sid number(5),sname char(5),gender char(5),doj char(10),bid
number(5),cid number(5),foreign key (bid),foreign key (cid));

1) Write a query to display the details of those students who joined on the same
date along with ASTHA.
Select * from student

where doj in( select doj from student where name =ASTHA);

2) Write a query to display the details of students who belong to the batches
handled by the faculty whose qualification is MBA.
Select * from student
Where cid in( select cid from batch
Where fid in( select fid in faculty where qualification = MBA));

3) Write a query to display the details of the faculty members who did not take
any batch in the last 3 months.
Select * from faculty
Where fid in (select fid from batch where end_date not between 30-01-2015
and 30-04-2015);

4) Write a query to display the details of batches which are handled by the
faculty whose qualification is MS or if the course fee is more than 5000.
select * from batch
where fid in( select fid from faculty where qualification = MS)
or cid in ( select cid from course where fee> 5000);

5) Write a query to display the details of students whose batch start date is '11jan-13'.
select * from student
where bid in( select bid from batch where start_date =11-01-2013);

6) Write a query to increase the course fee by 10% if more than 5 batches have
started for that course.
update course
set fee = fee*1.1
wherecid in (select cid from batch where
(select count(*) from batch group by cid) > 5);

7) Write a query to remove the batches where there are no students available.
delete * from batch
wherecid in ( select cid from student
where (select count(*) from student group by cid =0));

8) Write a query to display the course name and fee for the fifth highest course
fee.
select cname,fee from
(select cname, fee from course order by fee desc) where rownum = 5;

9) Write a query to display the course names whose fee is more than any
course whose duration is 30.
select cname from course
where fee>( select max( fee) from(select fee from course where cid in
(select cid from batch where duration =30)));

10) Write a query to create a table new_course from the existing course table of
those courses whose duration is 45.
create table newcourse as (select * from course where duration =45);

Vous aimerez peut-être aussi