zoukankan      html  css  js  c++  java
  • C++使用cin.getline使用例题

     1 #include<iostream>
     2 #include<cstring>
     3 #include<stdio.h>
     4 using namespace std;
     5 class stu{
     6     private:
     7         char name[32];
     8         char ID[32];
     9         int age;
    10         int score[4];
    11         int avg_score;
    12     public:
    13         void getDate(char Name[],char id[],int Age);
    14         void score_avrg(int score1[],int score2[],int score3[],int score4[]);
    15         void printfDate();
    16 };
    17 
    18 void stu::getDate(char Name[],char id[],int Age)
    19 {
    20     strcpy(name,Name);//利用数据传参进行对类内成员变量的修改
    21     strcpy(ID,id);
    22     age=Age;
    23 }
    24 
    25 void stu::printfDate()
    26 {
    27     cout<<name<<","<<age<<","<<ID<<","<<avg_score<<endl;
    28 }
    29 
    30 void stu::score_avrg(int score1[],int score2[],int score3[],int score4[])
    31 {
    32     avg_score=(score1[0]+score2[0]+score3[0]+score4[0])/4;
    33 }
    34 
    35 int main(int argc,char *argv[])
    36 {
    37         char Name[32];
    38         char id[32];
    39         char a;
    40         int Age=0;
    41         int Score[4];
    42         stu m;//无论如何都得需要定义一个类的变量对类的成员函数进行修改
    43         cin.getline(Name,32,',');//此处“,”是表示结束符
    44         cin>>Age>>a;
    45         cin.getline(id,32,',');
    46         cin>>Score[0]>>a>>Score[1]>>a>>Score[2]>>a>>Score[3];
    47         m.getDate(Name,id,Age);//数据修改变量,传参为数组地址
    48         m.score_avrg(&Score[0],&Score[1],&Score[2],&Score[3]);
    49         m.printfDate();
    50         return 0;
    51 }

  • 相关阅读:
    MySQL >>> 存储引擎
    MySQL >>> 基本操作语句
    MySQL >>> 使用安装
    协程 *单线程实现并发
    进程池 & 线程池
    线程 *知识点扩充
    进程 & 线程
    DRF单表序列化
    DRF
    接口规范
  • 原文地址:https://www.cnblogs.com/dog-and-cat/p/6724346.html
Copyright © 2011-2022 走看看