c++ 播放器

效果:

 

//运行环境   dev c++ 5.9.2
#include <iostream>
#include <windows.h>  //Sleep函数调用的头文件 
#include <mmsystem.h> //媒体控制函数的头文件
//在VC2008和VC6.0环境中从此头文件 #pragma comment(lib, "winmm.lib") 
using namespace std;
 
class automobile
{
    private:
        char type[20];
        char color[20];
        float price;
        int carry_weight;
        int carry_customer;
    public:
        void set_date(char *t, char *c, float pri, int cw, int cc); //初始化或修改数据成员
        void movecar(int l, int k);
        void horming(int num);
        void downcar(int l);
        void play_mp3(char *ps);
        char *show_type()
        {
            return type;
        } 
        
};
 
void automobile::set_date(char *t, char *c, float pri, int cw, int cc)
{
    strcpy(type, t);
    strcpy(color, c);
    price = pri;
    carry_weight = cw;
    carry_customer = cc;
}
 
void automobile::movecar(int l, int k)
{
    cout<<"\n"<<type<<"水平直线运动:"<<endl;
    for(int i=0; i<l; i++)
    {
        cout<<' '<<"o-o";
        Sleep(1000/k);
        cout<<"\b\b\b";
        
    }
}
 
void automobile::downcar(int l)
{
    //垂直下降运动
    cout<<"\n"<<type;
    for(int i=0; i<l; i++)
    {
        cout<<"o_o";
        Sleep(500);
        cout<<"\b\b\b"<<" ";
        cout<<endl;
    }
}
 
void automobile::horming(int num)
{
    for(int i=0; i<num; i++)
    {
        cout<<type;
        cout<<"\007"<<"di.."<<endl;
        Sleep(1000);        
    }
}
 
void automobile::play_mp3(char *ps)
{
    char str[100]="play "; //play后面有空格
    strcat(str,ps);
    cout<<str;
    mciSendString(str, NULL, 0, NULL);
    //如果不进行如下操作的话:会报错误:
//    C:\Users\sjcnh\AppData\Local\Temp\cczFSVYd.o    Car.cpp:(.text+0x2c6): undefined reference to `__imp_mciSendStringA'
//    D:\060417\collect2.exe    [Error] ld returned 1 exit status 
    //在Dec-C++环境中还要进行设置;
    //工具\编译器选项\编译器\在连接器命令中加入一下命令-lwinmm
    //-static-libgcc 
    char a;
    cin>>a; //输入任何字符结束播放
}
 
int main()
{
    automobile nisson;
    char tp[]="奥迪A9";
    char ys[]="white";
    nisson.set_date(tp, ys, 200000, 5, 3);
    nisson.horming(5);
    nisson.movecar(10, 10);
    nisson.downcar(5);
    char mp[]="情深深雨濛濛-赵薇.mp3";
    nisson.play_mp3(mp);
    return 0;
//    1a2s3d45f67j8k90l90l
 
}
View Code

 

 

  

posted @ 2019-06-28 10:50  Tony小哥  阅读(882)  评论(0编辑  收藏  举报