PROGRAMMING –ASSIGNMENT 1



PROGRAMMING –ASSIGNMENT 11. 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 typeStudent Public member function of classTakedata() - 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; } 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 name23SonalEnter the marks of english,maths,science465768………Student details…..Admission number=23Student name=sonalEnglish marks=46Maths marks=57Science marks=68Total marks=171Enter 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: bcode4 digit code number bname20 charctersInnings,notout,runsInteger type batavgbatavg=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() { 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; 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:1Enter the bats man code:333Enter the bats man name:Chris GayleEnter innings,notout,runs9523563Bats man code:333Bats man name:Chris GayleBats man innings:95Bats man notout:2Bats man runs:3563Bats 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{ 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() { 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:45Enter the description:examEnter the no of candidates greater than 101:501Testcode:45Description:examNumber of candidates:501Centers required:4******************************END*********************************4. Define a class Flight in C++ with following description:Private MembersA 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 criteriaDistance Fuel<=1000 500more than 1000 and <=2000 1100more than 2000 2200Public 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>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() { 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(); flight f; f.feedinfoo(); f.showinfoo();getch();}SAMPLE OURPUT:Enter the flight no:45Enter*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: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; 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(); book b; b.input(); b.purchase(); getch();}SAMPLE OUTPUT:Enter bookno book tytle price of the book48Happiness3457Entr the number of copies to be purchased:7Total 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 >=60b] Marks in physics >=50c] Marks in chemistry >=40d] Total in all three subjects >=200orTotal in mathematics and physics >=150Given 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) 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:50Enetr the marks for phy sub:60Enter the marks for che sub:70sorry !!!!!candidate is not elgible for admission2. 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………………………………………………..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 bepaid 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{ 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)); 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){ 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:178pls select your type of cloth:1.Mill cloth 2.Handloom item1 Total amount you have to pay :170if u want to continue then press Y or else N:ypls enter your amount:90pls select your type of cloth:1.Mill cloth 2.Handloom item1 Total amount you have to pay :90if u want to continue then press Y or else N:ypls enter your amount:370pls select your type of cloth:1.Mill cloth 2.Handloom item2 Total amount you have to pay :315if u want to continue then press Y or else N:n________________________________________END________________________________________3. Write a program to find the number of and sum of all integers greater than 100and 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); } } SAMPLE OUTPUT: The number which is diisible by 7 :105The number which is diisible by 7 :112The number which is diisible by 7 :119The number which is diisible by 7 :126The number which is diisible by 7 :133The number which is diisible by 7 :140The number which is diisible by 7 :147The number which is diisible by 7 :154The number which is diisible by 7 :161The number which is diisible by 7 :168The number which is diisible by 7 :175The number which is diisible by 7 :182The number which is diisible by 7 :189The number which is diisible by 7 :196The sum of numbers :2107The total num of integers:14 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download