programming –assignment 1 · web viewto allow user to enter values for flight number,...

31
PROGRAMMING –ASSIGNMENT 1 1. Define a class student with the following specification: Private members of class student Admno interger sname 20 character Eng,math,science float Total float Ctotal() a function to calculate eng+math+science with float return type Student Public member function of class Takedata() - Function to accept values for admno, sname, eng, math, science and invoke ctotal() to calculate total. Showdata() - Function to display all the data members on the screen. #include<iostream.h> #include<conio.h> class student {

Upload: phamkhanh

Post on 21-Mar-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

PROGRAMMING –ASSIGNMENT 1

1. Define a class student with the following specification:Private members of class student

Admno interger sname 20 characterEng,math,science float Total float Ctotal() a function to calculate

eng+math+science with float return type

Student Public member function of class

Takedata() - Function to accept values for admno, sname, eng, math, science andinvoke ctotal() to calculate total.

Showdata() - Function to display all the data members on the screen.

#include<iostream.h>#include<conio.h>class student{ private: int admno; char sname[20]; float eng,math,sci; float total; void ctotal(){ total=eng+math+sci; }

Page 2: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

public: void takedat(){ cout<<"\n Enter admission no,student name"<<"\n"; cin>>admno>>sname; cout<<"Enter marks of english,maths,science"<<"\n"; cin>>eng>>math>>sci; ctotal(); ] void showdata(){ cout<<”……..Student details……..”<<”\n”; cout<<"Admission number="<<admno<<"\n"; cout<<"Student name:"<<sname<<"\n"; cout<<"English marks:"<<eng<<"\n"; cout<<"Maths marks:"<<math<<"\n"; cout<<"Science marks:"<<sci<<"\n"; cout<<"Total marks:"<<total; } };

void main() { clrscr(); student s[50]; int n,i; cout<<"Enter the number of student:"<<"\n"; cin>>n; for(i=0;i<n;i++) { s[i].takedata(); s[i].showdata(); } getch();}

Sample output:

Enter the number of student:2Enter admission no,student name

Page 3: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

23SonalEnter the marks of english,maths,science465768………Student details…..Admission number=23Student name=sonalEnglish marks=46Maths marks=57Science marks=68Total marks=171

Enter admission no,student name24VinayakEnter the marks of English,maths,science909995………Student details…..Admission number=24Student name=vinayakEnglish marks=90Maths marks=99Science marks=95Total marks=284………………………………………..END………………………………………

2. Define a class Batsman with the following specifications:Private members:

bcode 4 digit code number

Page 4: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

bname 20 charctersInnings,notout,runs Integer type batavg batavg=runs/(innings-notout) Calavg() Fuction to compute batavg

Public members:readdata() - Function to accept value from bcode, name, innings, notout, runs and invokeThe function calcavg()displaydata() - Function to display the data members on the screen.

#include<iostream.h>

#include<conio.h>

class batsman

{

private:

long int bcode;

char bname[20];

float innings,notout,runs;

float batavg;

void calavg()

{

batavg=runs/(innings-notout);

}

public:

void readdata()

Page 5: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

{

cout<<"\n Enter batsman code:"<<"\n";

cin>>bcode;

cout <<"Enter bats name:"<<"\n";

cin>>bname;

cout<<"Enter innings,notout,runs"<<"\n";

cin>>innings>>notout>>runs;

calavg();

}

void displaydata()

{

cout<<"Bats man code:"<<bcode<<"\n";

cout<<"Bats name:"<<bname<<"\n";

cout<<"Bats man innings:"<<innings<<"\n";

cout<<"Bats man notout:"<<notout<<"\n";

cout<<"Bats man runs:"<<runs<<"\n";

cout<<"Bats man avg:"<<batavg<<"\n";

}

};

void main()

{

clrscr();

int n;

Page 6: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

batsman b[50];

cout<<"Enter the number of batsman:"<<"\n";

cin>>n;

for(int i=0;i<n;i++)

{

b[i].readdata();

b[i].displaydata();

}

getch();

}

SAMPLE OUTPUT:

Enter the number of bats man:1

Enter the bats man code:333

Enter the bats man name:Chris Gayle

Enter innings,notout,runs

95

2

3563

Bats man code:333

Bats man name:Chris Gayle

Bats man innings:95

Page 7: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

Bats man notout:2

Bats man runs:3563

Bats man avg:38.311829

****************************End******************************

3. Define a class TEST in C++ with following description:

Private Members

Test code Integer Description String Nos of Candidate Integer CenterReqd(number of centers required)

Integer

CALCNTR() To calculate and return the numbers of CenterReqd as(NoCandidates/100+1)

Public members:

SCHEDULE() - to allow user to enter values for TestCode, Description, NoCandidate,

& call function CALCNTR() to calculate the number of Centres.DISPTEST() - to allow user to view the content of all the data members

#include<iostream.h>

#include<conio.h>

class test

{

Page 8: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

private:

int testcode;

int nocad;

int cenreq;

char description[100];

void calcntr()

{

cenreq=(nocad)/(100+1);

}

public:

void schedule()

{

cout<<"Enter the test code:”<<”\N”;

cin>>testcode;

cout<<”Enter the description:”<<”\n”;

cin>>description;

cout<< “Enter the no of candidates greater than 101"<<"\n";

cin>>nocad;

calcntr();

}

void disptest()

{

Page 9: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

cout<<"Test code="<<testcode<<"\n";

cout<<"Description:"<<description <<"\n";

cout<<"Number of candidates:"<<nocad<<"\n";

cout<<"Centers required:"<<cenreq<<"\n";

}

};

void main()

{

clrscr();

test t;

t.schedule();

t.disptest();

getch();

}

SAMPLE OUTPUT:

Enter the test code:45

Enter the description:exam

Enter the no of candidates greater than 101:501

Testcode:45

Description:exam

Page 10: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

Number of candidates:501

Centers required:4

******************************END*********************************

4. Define a class Flight in C++ with following description:Private Members

A data member Flight number of type integerA data member Destination of type stringA data member Distance of type floatA data member Fuel of type floatA member function CALFUEL() to calculate the value of Fuel as per the following criteria

Distance Fuel<=1000 500more than 1000 and <=2000 1100more than 2000 2200

Public Members

- A function FEEDINFO() to allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel- A function SHOWINFO() to allow user to view the content of all the data members

#include<iostream.h>

#include<conio.h>

Page 11: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

class flight

{

private:

int fno;

char dest[10];

float dist;

float fuel;

float calfuel(float k)

{

float total;

if(k<=1000)

total=500;

else if((k>1000)&&(k<=2000))

{

total=1100;

}

else{

total=2200;

}

return total;

}

public:

void feedinfoo()

Page 12: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

{

cout<<"Enter the flight no:";

cin>>fno;

cout<<"\nEnter\n*destination:";

cin>>dest;

cout<<"\n*distance:";

cin>>dist;

float total;

total=calfuel(dist);

}

void showinfoo()

{

float total;

cout<<"\n\n\t********INFORMATION*********";

cout<<"\n*Flight number:"<<fno;

cout<<"\n*Destination:"<<dest;

cout<<"\n*Distance:"<<dist<<"k.m";

cout<<"\n*Total fuel required:"<<total<<"litr"<<"\n";

}

};

void main()

{

clrscr();

Page 13: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

flight f;

f.feedinfoo();

f.showinfoo();

getch();

}

SAMPLE OURPUT:

Enter the flight no:45

Enter

*Destination:Deli

*Distance:2000

**********INFORMATION*********

*Flight number:45

*Destination:Deli

*Distance:2000 k.m

*Total fuel required:1100 litr

*****************************END*****************************

5. Define a class BOOK with the following specifications :Private members of the class BOOK are:

Page 14: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

BOOK NO integer typeBOOKTITLE 20 charactersPRICE float (price per copy)TOTAL_COST() A function to calculate the total cost for N number of copies where N is passed to the function as argument.

Public members of the class BOOK are:INPUT() - function to read BOOK_NO. BOOKTITLE, PRICEPURCHASE() - function to ask the user to input the number of copies to be purchased.It invokes TOTAL_COST() and prints the total cost to be paid by the user.Note : You are also required to give detailed function definitions.

#include<iostream.h>

#include<conio.h>

class book

{

private:

int bno;

char btytle[20];

float price;

float total_cost(int x)

{

float total;

total=price*x;

Page 15: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

return total;

}

public:

void input()

{

cout<<"\nEnter book no\tbook tytle\tprice of the book"<<"\n";

cin>>bno;

cin>>btytle;

cin>>price;

}

void purchase()

{

cout<<"Enter the number of copies to be purchased"<<"\n";

int n;

cin>>n;

float total;

total=total_cost(n);

cout<<"Total cost to be paid by the user:"<<total<<"/- rupees"<<"\n";

}

};

void main()

{

clrscr();

Page 16: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

book b;

b.input();

b.purchase();

getch();}

SAMPLE OUTPUT:

Enter bookno book tytle price of the book

48

Happiness

3457

Entr the number of copies to be purchased:7

Total cost to be paid by the user:24199/-

******************************END******************************

PROGRAMMING ASSIGNMENT -2

1. Admission to a professional course is subject to the following conditions:a] Marks in mathematics >=60

b] Marks in physics >=50

Page 17: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

c] Marks in chemistry >=40

d] Total in all three subjects >=200

or

Total in mathematics and physics >=150

Given the marks in the three subjects, write a program to process the applications to the eligible candidates.

import java.io.BufferedReader;

import java.io.*;

public class Admission {

public static void main(String args[])throws Exception{

BufferedReader br=new BufferedReader(newInputStreamReader(System.in));

int math,phy,chem,total;

System.out.println("Enter the marks for maths sub:");

math=Integer.parseInt(br.readLine());

System.out.println("Enetr the marks for phy sub:");

phy=Integer.parseInt(br.readLine());

System.out.println("Enter the marks for che sub:");

chem=Integer.parseInt(br.readLine());

total=math+phy+chem;

if((math>=60)&&(phy>=50)&&(chem>=40))

System.out.println(" congrats!!!!....candidate is elgible for the admission ");

else if(total>=200)

Page 18: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

System.out.println(" congrats!!!!....candidate is elgible for the admission ");

else

{

if((math+phy)>=150)

System.out.println(" congrats!!!!....candidate is elgible for thadmission ");

else

System.out.println("sorry !!!!!candidate is not elgible for admission");

}

}

}

Sample output:

1.Enter the marks for maths sub:50

Enetr the marks for phy sub:60

Enter the marks for che sub:70

sorry !!!!!candidate is not elgible for admission

2. Enter the marks for maths sub:70

Enetr the marks for phy sub:80

Enter the marks for che sub:85

congrats!!!!....candidate is elgible for the admission

…………………………………END………………………………………………..

Page 19: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

2. A cloth showroom has announced the followingseasonal discounts on purchaseof items:Discount Mill Cloth Handloom items

0 - 100 -- 5.0 %

101 - 200 5.0 % 7.5 %

201 - 300 7.5 % 10.0 %

Above 300 10.0 % 15.0 %

Write a program using switch and if statements to compute the net amount to be

paid by a customer.

import java.io.BufferedReader;

import java.io.*;

import java.util.*;

public class Discount {

public static void main(String args[]) throws Exception{

BufferedReader br=new BufferedReader(newInputStreamReader(System.in));

Scanner scan=new Scanner(System.in);

int ch,total,am;

String answer="";

do{

Page 20: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

System.out.println("pls enter your amount");

am=Integer.parseInt(br.readLine());

System.out.println("pls select your type of cloth:");

System.out.println("1.Mill cloth");

System.out.println("2.Handloom item");

ch=Integer.parseInt(br.readLine());

switch(ch)

{

case 1:

if(am<=301)

{

if(am<101)

{

System.out.println(" Total amount you have to pay :");

total=am;

System.out.println(+total);

}

else

{

if(am<201)

{

System.out.println(" Total amount you have to pay :");

total=(am)-((am*5)/(100));

Page 21: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

System.out.println(+total);

}

else

{

System.out.println(" Total amount you have to pay :");

total=(am)-((am*7)/(100));

System.out.println(+total);

}

}

}

else {

System.out.println(" Total amount you have to pay :");

total=(am)-((am*10)/(100));

System.out.println(+total);}

break;

case 2:

if(am<=301){

if(am<101){

System.out.println(" Total amount you have to pay :");

total=(am)-((am*5)/(100));

System.out.println(+total);}

else{

if(am<=201){

Page 22: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

System.out.println(" Total amount you have to pay :");

total=(am)-((am*7)/(100));

System.out.println(+total);}

else {

System.out.println(" Total amount you have to pay :");

total=(am)-((am*10)/(100));

System.out.println(+total);}}}

else {

System.out.println(" Total amount you have to pay :");

total=(am)-((am*15)/(100));

System.out.println(+total);}

break;

}

System.out.println("if u want to continue then press Y or else N:");

answer=scan.next();

}while(answer.equals("y"));

}

}

SAMPLE OUTPUT:

1. pls enter your amount:178

pls select your type of cloth:1.Mill cloth

2.Handloom item

Page 23: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

1

Total amount you have to pay :170

if u want to continue then press Y or else N:

y

pls enter your amount:90

pls select your type of cloth:1.Mill cloth

2.Handloom item

1

Total amount you have to pay :90

if u want to continue then press Y or else N:

y

pls enter your amount:370

pls select your type of cloth:1.Mill cloth

2.Handloom item

2

Total amount you have to pay :315

if u want to continue then press Y or else N:n

________________________________________END________________________________________

Page 24: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

3. Write a program to find the number of and sum of all integers greater than 100

and less than 200 that are divisible by 7.

Import java.io.*;

public class HelloWorld{

public static void main(String[] args) {

int sum=0;

int count=0;

for(int i=100;i<=200;i++)

{

if(i%7==0){

System.out.print("The number which is diisible by 7 :");

System.out.println(i);

sum=sum+i;

count++;}

}

System.out.print("The sum of numbers :"+sum);

System.out.println("The total num of integers:"+count);

}

}

Page 25: PROGRAMMING –ASSIGNMENT 1 · Web viewto allow user to enter values for Flight Number, Destination,Distance & call function CALFUEL() to calculate the quantity of Fuel

SAMPLE OUTPUT:

The number which is diisible by 7 :105

The number which is diisible by 7 :112

The number which is diisible by 7 :119

The number which is diisible by 7 :126

The number which is diisible by 7 :133

The number which is diisible by 7 :140

The number which is diisible by 7 :147

The number which is diisible by 7 :154

The number which is diisible by 7 :161

The number which is diisible by 7 :168

The number which is diisible by 7 :175

The number which is diisible by 7 :182

The number which is diisible by 7 :189

The number which is diisible by 7 :196

The sum of numbers :2107

The total num of integers:14