| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 495 人关注过本帖
标题:请帮我看看要怎么改~! 謝謝~!!!
只看楼主 加入收藏
unknowchiu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-12-11
结帖率:0
收藏
 问题点数:0 回复次数:1 
请帮我看看要怎么改~! 謝謝~!!!
请帮我看看要怎么改~!謝謝~!!!
must write the subprogram to share individual elements of the array -- NOT the whole array. In your loops in main, call the subprogram once for each element of the array.

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

const int size = 3;

struct student
{
  string name;
  string address;
  string city;
  string state;
  int zip;
  char gender;
  int idno;
  float gpa;
}; //student

void getInfo(int i, student* s)
{
// function to get students' information
  cout << "student " << i+1 << "'s Name? ";
  getline(cin, s[i].name);

  cout << "student " << i+1 << "'s address? ";
  getline(cin, s[i].address);

  cout << "student " << i+1 << "'s city? ";
  getline(cin, s[i].city);

  cout << "student " << i+1 << "'s state? ";
  getline(cin, s[i].state);

  cout << "student " << i+1 << "'s zip code? ";
  cin >> s[i].zip;
  cin.ignore(1000, 10);

  cout << "student " << i+1 << "'s gender? [M/F]";
  cin >> s[i].gender;
  cin.ignore(1000, 10);

  cout << "student " << i+1 << "'s ID number? ";
  cin >> s[i].idno;
  cin.ignore(1000, 10);
   
  cout << "student " << i+1 << "'s gpa? ";
  cin >> s[i].gpa;
  cin.ignore(1000, 10);
   
  cout << endl;
}

// function to print students' information
void printInfo(int i, student* s)
{
  cout << "=======student (" << i+1 << ")=======" << endl;
  cout << "Name: " << s[i].name << endl;
  cout << "Address: " << s[i].address << endl;
  cout << "City: " << s[i].city << endl;
  cout << "State: " << s[i].state << endl;
  cout << "Zip code: " << s[i].zip << endl;
  cout << "Gender: " << s[i].gender << endl;
  cout << "ID number: " << s[i].idno << endl;
  cout << "GPA: " << s[i].gpa << endl;
  cout << endl;
}

int main()
{
  PrintStatements();

  student s[2];
  int i;

  for (i = 0; i < size; i++)
  {
    getInfo(i, s);
  } //getInfo

  cout << endl;

  for (i = 0; i < size; i++)
  {
    printInfo(i, s);
  } //printInfo

// End!
  cout << endl;
  cout << endl;
  cout << "Press ENTER to continue..." << endl;
  cin.get();
  return 0;
}
搜索更多相关主题的帖子: individual elements address include whole 
2011-12-11 09:24
主公不在家
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-14
收藏
得分:0 
must write the subprogram to share individual elements of the array -- NOT the whole array. In your loops in main, call the subprogram once for each element of the array.
这个不就是提示错误的地方吗?数组的问题,循环的地方
2011-12-14 21:05
快速回复:请帮我看看要怎么改~! 謝謝~!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013757 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved