Primer_seven

#include <iostream>

using namespace std;
double average(double num_1,double num_2);
int main()
{
    double num_1,num_2,ave;
    do
    {
        cout << "请输入第一个数:"<<endl;
        cin >>num_1;
        cout <<"请输入第二个数:"<<endl;
        cin >>num_2;
        ave=average(num_1,num_2);
        cout <<"调和平均数为:"<<ave<<endl;
    }while(num_1!=0&&num_2!=0);
    return 0;
}
double average(double num_1,double num_2)
{
    return 2.0*num_1*num_2/(num_1+num_2);
}


#include <iostream>
void input(double arr[]);
void show(double arr[]);
double average(double arr[]);
const int Size=10;
using namespace std;

int main()
{
    double arr[Size];
    input(arr);
    show(arr);
    cout <<"平均成绩为:"<<average(arr)<<endl;

    return 0;
}
void input(double arr[])
{
    cout <<"请输入最多十个高尔夫成绩(结束,输入-1):"<<endl;
    for(int i=0;i<10;i++)
    {
        cin>>arr[i];
        if(arr[i]==-1)
        {
            for(;i<10;i++)
            {
                arr[i]=0;
            }
            break;
        }

    }
}
void show(double arr[])
{
    cout <<"成绩分别是:"<<endl;
    for(int i=0;i<10;i++)
    {
        cout <<arr[i]<<"    ";
    }
    cout <<endl;
}
double average(double arr[])
{
    double sum=0;
    int i;
    for(i=0;i<10;i++)
    {
        if(arr[i]==0&&arr[i+1]==0)
            break;
        sum+=arr[i];

    }
    return sum/i;
}

#include <iostream>

using namespace std;
struct box
{
    char maker[40];
    float height;
    float width;
    float length;
    float volume;
};
void show(box b);
void setbox(box *pb);
int main(void)
{
    box carton={"Bingo boxer",2,3,5};
    setbox(&carton);
    show(carton);
    return 0;
}
void show(box b)
{
    cout << "Box maker: " << b.maker
         << "\nheight: " << b.height
         << "\nlwidth: " << b.width
         << "\nlength: " << b.length
         << "\nvolume: " << b.volume << "\n";
}
void setbox(box *pb)
{
    pb->volume=pb->height*pb->width*pb->length;
}

#include <iostream>

using namespace std;
long double probability(unsigned numbers,unsigned picks);
int main()
{
    double total,choices;
    double mtotal;
    double probability1,probability2;
    cout << "Enter total number of game card choices and\n"
            "number of picks allowed for the field:\n";
    while((cin>>total>>choices)&&choices<=total)
    {
        cout<<"Enter total number of game card choices "
              "for the mega number\n";
        if(!(cin>>mtotal))
            break;
        cout << "The chances of getting all " << choices << " picks is one in"

             << (probability1 = probability(total, choices) ) << ".\n";
        cout << "The chances of getting the megaspot is one in "
             << (probability2 = probability(mtotal, 1) ) << ".\n";
        cout << "You have one chance in ";
        cout << probability1 * probability2;
        cout << " of winning.\n";
        cout << "Next set of numbers (q to quit): ";

    }
    return 0;
}
long double probability(unsigned numbers,unsigned picks)
{
    long double result=1.0;
    long double n;
    unsigned p;
    for (n = numbers, p = picks; p > 0; n--, p--)
        result = result * n / p;
    return result;

}

#include <iostream>
void recursive(int n);
using namespace std;
int result=1;
int main()
{
    cout<<"Please enter a number N: "<<endl;
    int n;
    while(cin>>n)
    {
        if(n<0)
        {
            cout<<"error,please enter again"<<endl;
            continue;
        }
        recursive(n);
        cout<<"Please enter a number N(q to quit): "<<endl;
    }
    return 0;
}
void recursive(int n)
{

    result*=n;
    if(n>1)
        recursive(n-1);
    if(n==1)
        cout<<"n!= "<<result<<endl;

}

#include <iostream>
int Fill_array(double ar[],int size);
void show(const double ar[],int size);
void Reverse_array(double ar[],int size);
using namespace std;
const int LIMIT=10;
int main()
{
    double values[LIMIT];
    int entries = Fill_array(values, LIMIT);
    cout << "Array values:\n";
    show(values, entries);
    cout << "Array reversed:\n";
    Reverse_array(values, entries);
    show(values, entries);
    cout << "All but end values reversed:\n";
    Reverse_array(values+1, entries-2);
    show(values, entries);


    return 0;
}
int Fill_array(double ar[],int size)
{
    cout<<"Enter up to "<<size<<" values(q to quit): "<<endl;
    int n;
    for(n=0;n<size;n++)
    {
        cin>>ar[n];
        if(!cin)
            break;
    }
    return n;
}
void Reverse_array(double ar[],int size)
{
    int temp,i,j;
    for(i=0,j=size-1;i<j;i++,j--)
    {
        temp=ar[i];
        ar[i]=ar[j];
        ar[j]=temp;
    }
}
void show(const double ar[],int size)
{
    int n;
    for (n = 0; n < size; n++)
    {
        cout << ar[n];
        if (n % 8 == 7)
            cout << endl;
        else
            cout << ' ';
    }
    if (n % 8 != 0)
        cout << endl;

}



#include <iostream>
double *Fill_array(double *head,double *max);
void show(double *head,double *tail);
void Reverse_array(double *head,double *tail);
using namespace std;
const int LIMIT=10;
int main()
{
    double values[LIMIT];
    double *head;
    double *tail;
    head=&values[0];
    tail=Fill_array(head,head+LIMIT);
    cout << "Array values:\n";
    show(head,tail);
    cout << "Array reversed:\n";
    Reverse_array(head,tail);
    show(head, tail);
    cout << "All but end values reversed:\n";
    Reverse_array(head+1, tail-1);
    show(head,tail);


    return 0;
}
double *Fill_array(double *head,double *max)
{
    cout<<"Enter up to "<<LIMIT<<" values(q to quit): "<<endl;
    double *p=head;
    for(;p<max;p++)
    {
        cin>>*p;
        if(!cin)
            break;
    }
    return p-1;
}
void Reverse_array(double *head,double *tail)
{
    double temp;
    double *head1=head;
    double *tail1=tail;
    cout <<*head<<*tail<<endl;
    for(;head1<=tail1;head1++,tail1 --)
    {
        temp=*head1;
        *head1=*tail1;
        *tail1=temp;
    }
}
void show(double *head,double *tail)
{
   double *head1=head;
   double *tail1=tail;
   while(head1<=tail1)
   {
       cout<<*head1<<"   ";
       head1++;

   }
   cout<<endl;

}

#include <iostream>

using namespace std;

const int SLEN=30;
struct student
{
    char fullname[SLEN];
    char hobby [SLEN];
    int ooplevel;
};
int getinfo(student pa[],int n);
void display1(student st);
void display2(const student *ps);
void display3(const student pa[],int n);
int main()
{
    cout <<"Enter class size: ";
    int class_size;
    cin>>class_size;
    while (cin.get()!='\n')
        continue;
    student *ptr_stu=new student[class_size];
    int entered = getinfo(ptr_stu,class_size);
    for(int i=0;i<entered;i++)
    {
        display1(ptr_stu[i]);
        display2(&ptr_stu[i]);
    }
    display3(ptr_stu,entered);
    delete[]ptr_stu;
    cout << "Done\n";
    return 0;
}
int getinfo(student pa[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
         cout << "Please enter this student's fullname: ";
         int j;
         cin.get(pa[i].fullname[0]);
         if (pa[i].fullname[0] == '\n')
         {
             break;
         }

         for (j = 1; j < SLEN && (pa[i].fullname[j-1] != '\n'); ++j)
         {
             cin.get(pa[i].fullname[j]);
             pa[i].fullname[j+1] = '\0';
         }
         cout << "Please enter this student's hobby: ";
         cin >> pa[i].hobby;
         cout << "Please enter this student's ooplevel: ";
         cin >> pa[i].ooplevel;
         cin.get();

    }
    return i;
}
void display1(student st)
{
    cout<<st.fullname<<'\t'<<st.hobby<<'\t'<<st.ooplevel<<endl;
}
void display2(const student *ps)
{
    cout<<(ps->fullname)<<'\t'<<(ps->hobby)<<'\t'<<(ps->ooplevel)<<endl;
}
void display3(const student pa[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(pa[i].fullname=="")
            break;
        cout<<pa[i].fullname<<'\t'<<pa[i].hobby<<'\t'<<pa[i].ooplevel<<endl;
    }
}


#include <iostream>
double calculate(double x,double y,double (*pf)(double,double));
double add(double,double);
double multiplie(double,double);
using namespace std;

int main()
{
    cout <<"Please enter the first number: ";
    double x,y;
    cin >>x;
    cout <<"Please enter the second number: ";
    cin>>y;
    cout <<x<<" + "<<y<<" = "<<calculate(x,y,add)<<endl;
    cout <<x<<" * "<<y<<" = "<<calculate(x,y,multiplie)<<endl;
    return 0;
}
double calculate(double x,double y,double (*pf)(double,double))
{
    return pf(x,y);
}
double add(double x,double y)
{
    return x+y;
}
double multiplie(double x,double y)
{
    return x*y;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值