Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstring>
- using namespace std;
- class faction{
- int x;
- int y;
- public:
- faction(int a, int b){
- x=a;
- y=b;
- }
- faction(){
- x=0;
- y=0;
- }
- void setFrac(string a){
- if(a.size()==3){
- switch(a[0]){
- case '/':
- return;
- case '1':
- x=1;
- break;
- case '2':
- x=2;
- break;
- case '3':
- x=3;
- break;
- case '4':
- x=4;
- break;
- case '5':
- x=5;
- break;
- case '6':
- x=6;
- break;
- case '7':
- x=7;
- break;
- case '8':
- x=8;
- break;
- case '9':
- x=9;
- break;
- case '0':
- x=0;
- break;
- default:
- return;
- }
- switch(a[1]){
- case '/':
- break;
- default:
- return;
- }
- switch(a[2]){
- case '/':
- return;
- case '1':
- y=1;
- break;
- case '2':
- y=2;
- break;
- case '3':
- y=3;
- break;
- case '4':
- y=4;
- break;
- case '5':
- y=5;
- break;
- case '6':
- y=6;
- break;
- case '7':
- y=7;
- break;
- case '8':
- y=8;
- break;
- case '9':
- y=9;
- break;
- case '0':
- y=0;
- break;
- default:
- return;
- }
- }
- }
- void getFrac(){
- cout<<x<<"/"<<y<<endl;
- }
- int getX(){
- return x;
- }
- int getY(){
- return y;
- }
- void sumFrac(faction a){
- x=x+a.getX();
- y=y+a.getY();
- getFrac();
- }
- };
- int main() {
- faction a(0, 0);
- faction b(0, 0);
- faction c(0, 0);
- string a1="y";
- string b1;
- while(a1=="y"){
- cin>>b1;
- a.setFrac(b1);//
- cin>>b1;
- b.setFrac(b1);//
- a.sumFrac(b);//
- cout<<"Wanna continue? y/n"<<endl;
- a1="n";
- cin>>a1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement