Advertisement
StoneHaos

main.cpp

Mar 5th, 2020
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <cstdio>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5. #include "lib.h"
  6.  
  7. Software::Software() {
  8.     this->name = "unknown";
  9.     this->type = "unknown";
  10.     this->author = "unknown";
  11. }
  12.  
  13. Software::Software(string name, string type, string author) {
  14.     this->name = name;
  15.     this->type = type;
  16.     this->author = author;
  17. }
  18.  
  19. string Software::get(int var) {
  20.     if (var >= 0 && var <= 2) {
  21.         if (var)
  22.             return (var == 1) ? this->type : this->author;
  23.         else
  24.             return this->name;
  25.     }
  26.     else
  27.         return "";
  28. }
  29.  
  30. void Software::set(int var, string value) {
  31.     if (var >= 0 && var <= 2) {
  32.         if (var == 0)
  33.             this->name = value;
  34.         else if (var == 1)
  35.             this->type = value;
  36.         else
  37.             this->author = value;
  38.     }
  39. }
  40.  
  41. void Software::print() {
  42.     printf("Software:\nname: %s\ntype: %s\nauthor: %s\n", this->name.c_str(), this->type.c_str(), this->author.c_str());
  43. }
  44.  
  45. int main(void) {
  46.     Software a("name", "type", "author");
  47.     a.print();
  48.     printf("\n");
  49.     a.set(sw_name, "---");
  50.     a.print();
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement