My Diary.
to Share my Life Events

[C++] Nhập vào 2 phân số. So sánh và đưa ra phân số lớn hơn.

 Đề: Nhập vào 2 phân số. So sánh và đưa ra phân số lớn hơn.

#include<iostream>
using namespace std;
struct Fraction{
    int Enum;
    int Deno;
};
main(){
    Fraction frac1,frac2;
    cout<<"Enter Fraction 1: "<<endl;
    cout<<"Enumerator: ";
    cin>>frac1.Enum;
    cout<<"Denomirator: ";
    cin>>frac1.Deno;
   
    cout<<"Enter Fraction 2: "<<endl;
    cout<<"Enumerator: ";
    cin>>frac2.Enum;
    cout<<"Denomirator: ";
    cin>>frac2.Deno;
       
    system("cls");
   
    float ffrac1= float (frac1.Enum)/ frac1.Deno;
    float ffrac2= float (frac2.Enum) / frac2.Deno;
   
    if(ffrac1 > ffrac2)     cout<<"THE BIGGER FRACTION IS: "<<frac1.Enum<<"/"<<frac1.Deno;
    else
    if(ffrac1 = ffrac2)     cout<<"TWO FRACTONS IS EQUIVALENT";
    else
    cout<<"THE BIGGER FRACTION IS: "<<frac2.Enum<<"/"<<frac2.Deno;
}
Unknown Unknown Author

[C++] Viết chương trình nhập vào tọa độ 2 điểm A và B. Xuất ra khoảng cách AB

Đề: Viết chương trình nhập vào tọa độ 2 điểm A và B. Xuất ra khoảng cách  AB


#include<iostream>
#include<math.h>
using namespace std;
struct Coordinates{
    int abscissae;
    int absolute;
};
main(){
    Coordinates PointA,PointB;
    cout<<"Enter the coodinates of point A:\n";
    cout<<"Abscissae:";
    cin>>PointA.abscissae;
    cout<<"Absolute:";
    cin>>PointA.absolute;
   
    system("cls");
   
    cout<<"Enter the coodinates of point B:\n";
    cout<<"Abscissae";
    cin>>PointB.abscissae;
    cout<<"Absolute";
    cin>>PointB.absolute;
    system("cls");
   
    float a,b,Distance;
    cout<<"DISTANCE FROM POINT A TO POINT B IS: ";
    a=PointA.abscissae-PointB.abscissae;
    b=PointB.absolute-PointA.absolute;
    Distance= sqrt(pow(a,2)+pow(b,2));
    cout<<Distance<<endl;
}
Unknown Unknown Author

[C++] Nhập vào ngày hôm nay. Xuất ra hôm sau là ngày nào?

Đề: Nhập vào ngày hôm nay. Xuất ra hôm sau là ngày nào

#include<iostream>
using namespace std;
struct Date{
    int day;
    int month;
    int year;
};
bool checkLeapyear(int year){
    if(year%4==0 && year%10!=0) return true;
    else return false;
};
int checkMonth(int month){
    switch(month){
        case 1: case 3: case 5: case 7: case 8: case 10:
            return 1;
        case 4: case 6: case 9: case 11:
            return 2;
        case 2:
            return 3;
    }
}
main(){
    Date Date;
    cout<<("Enter Data:\n");
    cout<<("Day: ");
    cin>>Date.day;
    cout<<("Month: ");
    cin>>Date.month;
    cout<<("Year: ");
    cin>>Date.year;
    if(Date.day==31 && (checkMonth(Date.month)==1)){
        Date.day=1;
        Date.month++;
    };
    if(Date.day==30 && (checkMonth(Date.month)==2)){
        Date.day=1;
        Date.month++;
    };
    if(Date.day==28 && (checkMonth(Date.month)==3) && (checkLeapyear(Date.year)==false)){
        Date.day=1;
        Date.month++;
    };
    if(Date.day==29 && (checkMonth(Date.month)==3) && checkLeapyear(Date.year)==true){
        Date.day=1;
        Date.month;
    };
    if(Date.day==31 && Date.month==12){
        Date.day=1;
        Date.month=1;
        Date.year++;
    };
    system("cls");
    cout<<"THE NEXT DAY IS "<<Date.day<<" / "<<Date.month<<" / "<<Date.year;
}
Unknown Unknown Author

[C++] Nhập vào 1 phân số. Xác định nó là phân số âm, dương hay bằng không.


Đề bài: Nhập vào 1 phân số. Xác định nó là phân số âm, dương hay bằng không.

#include<iostream>
using namespace std;
struct Fraction{
    int enumerator;
    int denomirator;
};  
main(){
    Fraction *frac= new Fraction();
  
    cout<<"Please input the fraction:\n";
    cout<<"Enumeration a= :";
    cin>>frac->enumerator;
    cout<<"Denomirator b=:";
    cin>>frac->denomirator;
    system("cls");
    if((frac->enumerator >0 && frac->denomirator >0)||(frac->enumerator<0 && frac->denomirator <0)) cout<<"Positive fraction";
    if((frac->enumerator <0 && frac->denomirator >0)||(frac->denomirator<0 && frac->enumerator  >0)) cout<<"Negative fraction";
    if(frac->enumerator ==0 && frac->denomirator !=0)    cout<<"Zero fraction";
    delete frac;
};   
Unknown Unknown Author

Tags

Labels

Post Fomats

Featured Posts

Comments

Recent

Contact us

Tên

Email *

Thông báo *

Popular Posts

Popular