Last active
November 27, 2017 18:20
-
-
Save AhmedMourad0/1da460f25e5bdf3220add1325b36c82f to your computer and use it in GitHub Desktop.
College - Section - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/section.iml" filepath="$PROJECT_DIR$/.idea/section.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module classpath="CMake" type="CPP_MODULE" version="4" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.8) | |
project(section) | |
set(CMAKE_CXX_STANDARD 17) | |
set(SOURCE_FILES main.cpp) | |
add_executable(section ${SOURCE_FILES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
double calculateCharge(double); | |
bool isMultipleOf(long, long); | |
long reverseNumber(long); | |
int main() { | |
/* charge */ | |
double totalCharge = 0.0, totalHours = 0.0; | |
string output = "Car\t\tHours\t\tCharge\n"; | |
for (int i = 1; i <= 3; ++i) { | |
cout << "Enter the number of hours for car number " << i << ":\n"; | |
double hours; | |
cin >> hours; | |
double charge = calculateCharge(hours); | |
totalCharge += charge; | |
totalHours += hours; | |
output += to_string(i) + "\t\t" + to_string(hours).substr(0, 4) + "\t\t" + to_string(charge).substr(0, 4) + "\n"; | |
} | |
cout << output << "TOTAL\t\t" << totalHours << "\t\t" << totalCharge << endl; | |
cout << endl; | |
/* multiple of */ | |
cout << "Enter the number of pairs:\n"; | |
int numberOfPairs; | |
cin >> numberOfPairs; | |
for (int i = 1; i <= numberOfPairs; ++i) { | |
cout << "Enter pair number " << i << ":\n"; | |
long a, b; | |
cin >> a >> b; | |
if (isMultipleOf(a, b)) | |
cout << a << " is a multiple of " << b << ".\n"; | |
else | |
cout << a << " is not a multiple of " << b << ".\n"; | |
} | |
cout << endl; | |
/* reverse */ | |
cout << "Enter the number to reverse:\n"; | |
long numberToReverse; | |
cin >> numberToReverse; | |
cout << "Number: " << numberToReverse << "\tReversed: " << reverseNumber(numberToReverse) << endl; | |
return 0; | |
} | |
double calculateCharge(double hours) { | |
if (hours == 0.0) { | |
return 0.0; | |
} else if (hours > 0.0 && hours <= 3.0) { | |
return 2.0; | |
} else if (hours > 3.0) { | |
double charge = 2.0 + 0.5 * (hours - 3.0); | |
if (charge > 10.0) | |
return 10.0; | |
else | |
return charge; | |
} else { | |
return -1.0; | |
} | |
} | |
bool isMultipleOf(long a, long b) { | |
return a % b == 0; | |
} | |
long reverseNumber(long numberToReverse) { | |
long reversedNumber = 0; | |
while (numberToReverse != 0) { | |
long rightNumber = numberToReverse % 10; | |
reversedNumber = reversedNumber * 10 + rightNumber; | |
numberToReverse /= 10; | |
} | |
return reversedNumber; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment