Advertisement
fuadnafiz98

OOP

Apr 8th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <cstring>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. class Student {
  10. public:
  11.     char * name;
  12.     int id;
  13.     char * gender;
  14.     int level;
  15.  
  16.     void studentSet(char * n, int i, char *gen, int lvl) {
  17.         name = new char[strlen(n) + 1];
  18.         strcpy(name, n);
  19.         id = i;
  20.         gender = new char[strlen(gen) + 1];
  21.         strcpy(gender, gen);
  22.         level = lvl;
  23.     }
  24.     void studentShow() {
  25.         cout << "Name -> " << name << '\n';
  26.         cout << "Id -> " << id << '\n';
  27.         cout << "Gender -> " << gender << '\n';
  28.         cout << "Level -> " << level << '\n';
  29.     }
  30. };
  31.  
  32. class Exam : public Student {
  33. public:
  34.     char * examName;
  35.     int totalCourses;
  36.     int *marks;
  37.    void examSet(char *s, int i, int m[]) {
  38.     examName = new char[strlen(s) + 1];
  39.     strcpy(examName, s);
  40.     totalCourses = i;
  41.     marks = new int[totalCourses + 1];
  42.     for(int i = 0; i < totalCourses; i++) {
  43.         marks[i] = m[i];
  44.     }
  45.    }
  46.     void examShow() {
  47.         studentShow();
  48.         cout << "Exam Name -> " << examName << '\n';
  49.         cout << "Total courses -> " << totalCourses << '\n';
  50.         for(int i = 0; i < totalCourses; i++)
  51.             cout << "Marks -> " << marks[i] << '\n';
  52.     }
  53. };
  54.  
  55. class Result : public Exam {
  56. public:
  57.     int totalMarks() {
  58.         int res = 0;
  59.         for(int i = 0; i < totalCourses; i++)
  60.             res += marks[i];
  61.         return res;
  62.     }
  63.     bool ok = false;
  64.     void result() {
  65.         int cnt  = 0;
  66.         for(int i = 0; i < totalCourses; i++) {
  67.             if(marks[i] >= 40)
  68.                ok = true;
  69.             else {
  70.                 ok = false;
  71.                 cnt++;
  72.             }
  73.         }
  74.         if(ok) cout << "Passed in all subjects\n";
  75.         else cout << "Failed in " << cnt << " subjects\n";
  76.     }
  77. };
  78.  
  79.  
  80. class Movie{
  81. public:
  82.     char * movieName;
  83.     char * genre;
  84.     int releaseYear;
  85.     int duration;
  86.  
  87.     void movieSet(char * name, int year, int times, char * gen) {
  88.  
  89.         movieName = new char[strlen(name) + 1];
  90.         strcpy(movieName, name);
  91.         genre = new char[strlen(gen) + 1];
  92.         strcpy(genre, gen);
  93.         releaseYear = year;
  94.         duration = times;
  95.     }
  96.  
  97.     void movieShow() {
  98.         cout << "Movie Name -> " << movieName << '\n';
  99.         cout << "Release Year -> " << releaseYear << '\n';
  100.         cout << "Duration -> " << duration << '\n';
  101.         cout << "Genre -> " << genre << '\n';
  102.     }
  103. };
  104.  
  105. class Animation : public Movie {
  106. public:
  107.     char * graphicsCreator;
  108.     char * leadVocal;
  109.  
  110.     void set(char *gchar, char *vchar) {
  111.         graphicsCreator = new char[strlen(gchar) + 1];
  112.         leadVocal = new char[strlen(vchar) + 1];
  113.         strcpy(graphicsCreator, gchar);
  114.         strcpy(leadVocal, vchar);
  115.     }
  116.     void show() {
  117.         movieShow();
  118.         cout << "Graphics Creator -> " << graphicsCreator << '\n';
  119.         cout << "Lead Vocal -> " << leadVocal << '\n';
  120.     }
  121.  };
  122.  
  123. int main() {
  124.     Exam E;
  125.     Result R;
  126.     R.studentSet("Fuad", 42, "Male", 2);
  127.     int k[] = {10, 20, 30, 40, 50};
  128.     R.examSet("First", 5, k);
  129.     R.examShow();
  130.     R.result();
  131. }
  132.  
  133.  
  134.  
  135. ///
  136. #include <stdio.h>
  137. #include <iostream>
  138. #include <string>
  139. #include <cstring>
  140. #include <stdlib.h>
  141.  
  142. using namespace std;
  143.  
  144. class Person{
  145. public:
  146.     char * name;
  147.     int age;
  148.     char * gender;
  149.     void personSet(char * s, int a, char *gen) {
  150.         name = new char[strlen(s) + 1];
  151.         strcpy(name, s);
  152.         age = a;
  153.         gender = new char[strlen(gen) + 1];
  154.         strcpy(gender, gen);
  155.     }
  156.     void personShow() {
  157.         cout << "Name -> " << name << '\n';
  158.         cout << "Age -> " << age << '\n';
  159.         cout << "Gender -> " << gender << '\n';
  160.     }
  161. };
  162.  
  163. class Employee : public Person {
  164. public:
  165.     char * designation;
  166.     char * department;
  167.     int salary;
  168.     void employeeSet(char *occ, char * d, int t) {
  169.         designation = new char[strlen(occ) + 1];
  170.         strcpy(designation, occ);
  171.         department = new char[strlen(d) + 1];
  172.         strcpy(department, d);
  173.         salary = t;
  174.     }
  175.     void employeeShow() {
  176.         personShow();
  177.         cout << "Designation -> " << designation << '\n';
  178.         cout << "Department -> " << department << '\n';
  179.         cout << "Salary -> " << salary << '\n';
  180.     }
  181. };
  182.  
  183. class Customer : public Person {
  184. public:
  185.     char * accountType;
  186.     char * accountNo;
  187.     int balance;
  188.     void customerSet(char *s, char *a, int b) {
  189.         accountType = new char[strlen(s) + 1];
  190.         strcpy(accountType, s);
  191.         accountNo = new char[strlen(a) + 1];
  192.         strcpy(accountNo, a);
  193.         balance = b;
  194.     }
  195.     void showAll() {
  196.         personShow();
  197.         //employeeShow();
  198.         cout << "Account type -> " << accountType << '\n';
  199.         cout << "Account no -> " << accountNo << '\n';
  200.         cout << "Balance -> " << balance << '\n';
  201.     }
  202. };
  203.  
  204. int main() {
  205.     Customer C;
  206.     C.personSet("Fuad", 22, "Male");
  207.     //C.employeeSet("Teacher", "CSE", 30000);
  208.     C.customerSet("Normal", "101010", 45000);
  209.     C.showAll();
  210.  
  211. }
  212.  
  213. ////
  214.  
  215. #include <stdio.h>
  216. #include <iostream>
  217. #include <string>
  218. #include <cstring>
  219. #include <stdlib.h>
  220.  
  221. using namespace std;
  222.  
  223. class Department {
  224. private:
  225.     char * name;
  226. protected:
  227.     int id;
  228. public:
  229.     void set(char *c, int i) {
  230.         name = new char[strlen(c) + 1];
  231.         strcpy(name, c);
  232.         id = i;
  233.     }
  234.     void show() {
  235.         cout << name << ' ' << id << '\n';
  236.     }
  237. };
  238.  
  239. class Institute : public Department {
  240. private:
  241.     char *name;
  242. protected:
  243.     int id;
  244. public:
  245.     void set(char *c, int i, char *s, int j) {
  246.         Department :: set(s, j);
  247.         name = new char[strlen(c) + 1];
  248.         strcpy(name, c);
  249.         id = i;
  250.     }
  251.     void show() {
  252.         cout << Institute :: name << ' ' << Institute :: id << ' ' <<'\n';
  253.         Department ::show();
  254.     }
  255. };
  256.  
  257. int main(){
  258.     Institute I;
  259.     I.set("MIST", 10, "CSE", 20);
  260.     I.show();
  261. }
  262.  
  263. ///
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement