fork download
  1. // Lab 8, Working with structs
  2. // Programmer : Maiar Khattab
  3. // Editor(s) used : Code Blocks 13.12
  4. // Compiler(s) used : Code Blocks 13.12
  5.  
  6. #include<iostream>
  7. using std::cout;
  8. using std::endl;
  9.  
  10. #include<cstdlib>
  11.  
  12. //struct def
  13. struct tod
  14. {
  15. int hour;// the hr , 0-23
  16. int minute;// the min, 0-59
  17. int second;//the sec, 0-59
  18. char descr [32];//the description of the time of day
  19.  
  20. };
  21. //void printTod(const tod&);
  22. int main ()
  23. {
  24. cout << "Lab 8, Working With structs\n";
  25. cout << "Programmer: Maiar Khattab\n";
  26. cout << "Editor(s) used: Code Blocks 13.12\n";
  27. cout << "Compiler(s) used: Code Blocks 13.12\n";
  28. cout << "File: " << __FILE__ << endl;
  29. cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  30.  
  31. tod theTime[] = {{12,0,0, "noon"},
  32. {0,0,0," midnight"},
  33. {6,00,00," supper "},
  34. {11,30,0,"bedtime"}};
  35.  
  36. for(int i; i <5; i++)
  37. {
  38. char descr [32];
  39. cout << theTime[i].descr << " is " << theTime[i].hour << ':'
  40. << theTime[i].minute << ":" << theTime[i].second << endl;
  41. }
  42. }
  43.  
  44.  
Success #stdin #stdout 0.01s 5300KB
stdin
 
#include <iostream>
using namespace std;

//Regular Account  
void RegularAccount(int accountNumber, int minutes) {
    if(minutes < 50){
        cout << "Account number: " << accountNumber <<endl;
        cout << "Amount to pay:  R0";
    }
    else if(minutes >= 51){
        int amount = 100 + ((minutes - 50) * 2);
            cout << "Account number: " << accountNumber<<endl;
            cout << "Amount to pay: R"<<amount;
    }
}
//Premium Account
void DayMinutes(int accountNumber, int minutes){
    if (minutes <= 75){
        cout<< "Account Number: "<< accountNumber<<endl;
        cout<< "Amount to pay: R0"<<endl;
    }
    else if(minutes >=76){
        int amount = 250 + ((minutes - 75) * 1);
        cout<< "Account Number: "<< accountNumber<<endl;
        cout<< "Amount to pay: R"<<amount<<endl;
    }
}
void NightMinutes(int accountNumber, int minutes){
    if (minutes <= 100){
        cout<< "Account Number: "<< accountNumber<<endl;
        cout<< "Amount to pay: R0"<<endl;
    }
    else if(minutes >=101){
        int amount = 250 + (minutes - 100) * 0.5;
        cout<< "Account Number: "<< accountNumber<<endl;
        cout<< "Amount to pay: R"<<amount<<endl;
    }
}


int main() {

    int AccountNumber;
    cout << "Please enter your account number: ";
    cin >> AccountNumber;


    char ServiceCode;
    cout << "Please enter your service code: ";
    cin >> ServiceCode;
    ServiceCode = toupper(ServiceCode);

    int TotalMinutes, dayMinutes, nightMinutes;

    //Service Check
    switch (ServiceCode) {
        case 'R':
            cout << "Please enter number of minutes used: ";
            cin >> TotalMinutes;
            RegularAccount(AccountNumber, TotalMinutes);
            break;
        case 'P':
            cout << "Please enter number of minutes used during the day: ";
            cin >> dayMinutes;
            DayMinutes(AccountNumber, dayMinutes);

            cout << "Please enter number of minutes the service was 
stdout
Lab 8, Working With structs
Programmer: Maiar Khattab
Editor(s) used: Code Blocks 13.12
Compiler(s) used: Code Blocks 13.12
File: prog.cpp
Complied: Apr 23 2024 at 14:32:24

noon is 12:0:0
 midnight is 0:0:0
 supper  is 6:0:0
bedtime is 11:30:0
=7w; �f�H is 182312104:32766:-1266545152