cout<<"'A' to convert inch into centimenters \n'B' to convert, Assignments of Network security

if (conv=='A'||conv=='a') { cout<<"You choose to convert inch into centimeters"<<endl; cout<<"Enter the lengthe in inches: "; cin>>in; res= 2.54 * in; cout<<in<<" inches = "<<res<<" cm"<<endl; } else if (conv=='B' || conv=='b')

Typology: Assignments

2020/2021

Uploaded on 06/14/2021

kiran-shah
kiran-shah šŸ‡µšŸ‡°

3

(1)

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GIK Institute of Engineering Sciences & Technology
Faculty of Computer Science and Engineering
Time: 1.5 hours CS 102 Lab Max Marks: 10
Section: C Lab No: 11 April 24, 2018
Activity #01
Define a class Weapon with virtual function feature to print a message like ā€˜loading weapon
features’. Make two more classes Bomb and Gun. Inherit class Weapon in both of them and make
function feature in both and print a suitable message like above mentioned.
Define another class Loader with a function load_feature(). The prototype of this method may
be like:
void loadFeatures(Weapon *weapon)
Within this method, call the function feature of object weapon that is passed to this method.
In main(), make pointer objects of class Loader and Weapon. Another two objects of class Gun
and Bomb. Assign the addresses of Bomb and Gun class objects to the object of class weapon.
Call the Loader class method with weapon class object like:
w = &b;
l->loadFeatures(w);
w = &g;
l->loadFeatures(w);
Discuss what actually happens.
Solution:
1. #include <iostream>
2. using namespace std;
3.
4. class Weapon
5. {
6. public:
7. virtual void features()
8. { cout << "Loading weapon features.\n"; }
9. };
10.
11. class Bomb : public Weapon
12. {
13. public:
pf3
pf4
pf5

Partial preview of the text

Download cout<<"'A' to convert inch into centimenters \n'B' to convert and more Assignments Network security in PDF only on Docsity!

GIK Institute of Engineering Sciences & Technology

Faculty of Computer Science and Engineering

Time: 1 .5 hours CS 102 Lab Max Marks: 10

Section: C Lab No: 11 April 24, 2018

Activity

Define a class Weapon with virtual function feature to print a message like ā€˜loading weapon

features’. Make two more classes Bomb and Gun. Inherit class Weapon in both of them and make

function feature in both and print a suitable message like above mentioned.

Define another class Loader with a function load_feature(). The prototype of this method may

be like:

void loadFeatures(Weapon *weapon)

Within this method, call the function feature of object weapon that is passed to this method.

In main(), make pointer objects of class Loader and Weapon. Another two objects of class Gun

and Bomb. Assign the addresses of Bomb and Gun class objects to the object of class weapon.

Call the Loader class method with weapon class object like:

w = &b;

l->loadFeatures(w);

w = &g;

l->loadFeatures(w);

Discuss what actually happens.

Solution:

  1. #include
  2. using namespace std;
  3. class Weapon
  4. {
  5. public :
  6. virtual void features()
  7. { cout << "Loading weapon features.\n"; }
  8. };
  9. class Bomb : public Weapon
  10. {
  11. public :
  1. void features()
  2. { cout << "Loading bomb features.\n"; }
  3. };
  4. class Gun : public Weapon
  5. {
  6. public :
  7. void features()
  8. { cout << "Loading gun features.\n"; }
  9. };
  10. class Loader
  11. {
  12. public :
  13. void loadFeatures(Weapon *weapon)
  14. {
  15. weapon->features();
  16. }
  17. };
  18. int main()
  19. {
  20. Loader *l = new Loader;
  21. Weapon *w;
  22. Bomb b;
  23. Gun g;
  24. w = &b;
  25. l->loadFeatures(w);
  26. w = &g;
  27. l->loadFeatures(w);
  28. return 0;
  29. }

Activity

Define a class Shape with member variable length. Make a method getData() to input the

length and a pure virtual function calculate_area().

Make another two classes Square and Circle and implement the function

calculate_area().

In main(); make a pointer object of class Shape and assign it objects of Square and Circle

classes and call the method calculate_area() respectively.

  1. return 0;
  2. }

Activity

Define a class Student with class variable roll_no. Make a function getNumber() and

putNumber() to input and display the roll_no respectively.

Make another class Test from pure virtual base class Student. Make two class variables as part

and part2. Make two methods getMarks() and putMarks() to get and display the marks

respectively. The declaration of this class should be like:

class Test : virtual public Student {………}

Make another class Sports having two functions getScroe() and putScore() and derive it from

Student class as well. Make another class Result with member variable total to sum all the scores

and marks. You need to derive it from both the classes Test and Sports. Make a method to display

all the individual and total scores.

In main(), make the object of class Result and call all the methods with it.

Sample Output:

Enter Roll No: 200

Enter Marks

Part1: 90

Part2: 80

Enter Sports Score: 80

Roll No: 200

Marks Obtained

Part1: 90

Part2: 80

Sports Score is: 80

Total Score is: 250

Solution:

  1. #include<iostream.h>
  2. #include<conio.h>
  3. class student {
  1. int rno;
  2. public :
  3. void getnumber() {
  4. cout << "Enter Roll No:";
  5. cin>>rno;
  6. }
  7. void putnumber() {
  8. cout << "\n\n\tRoll No:" << rno << "\n";
  9. }
  10. };
  11. class test : virtual public student {
  12. public :
  13. int part1, part2;
  14. void getmarks() {
  15. cout << "Enter Marks\n";
  16. cout << "Part1:";
  17. cin>>part1;
  18. cout << "Part2:";
  19. cin>>part2;
  20. }
  21. void putmarks() {
  22. cout << "\tMarks Obtained\n";
  23. cout << "\n\tPart1:" << part1;
  24. cout << "\n\tPart2:" << part2;
  25. }
  26. };
  27. class sports : public virtual student {
  28. public :
  29. int score;
  30. void getscore() {
  31. cout << "Enter Sports Score:";
  32. cin>>score;
  33. }
  34. void putscore() {
  35. cout << "\n\tSports Score is:" << score;
  36. }
  37. };
  38. class result : public test, public sports {
  39. int total;
  40. public :
  41. void display() {
  42. total = part1 + part2 + score;
  43. putnumber();
  44. putmarks();
  45. putscore();
  46. cout << "\n\tTotal Score:" << total;
  47. }
  48. };
  49. void main() {
  50. result obj;