Hey everyone... I'm in a beginning C++ class right now and below is the code I've written for my current assignment... What I need to do is put all of the input code (basically the huge chunk of stuff from main, into a void function. I'm not quite sure how to do this. I was just introduced to structs and arrays, and had trouble understanding functions when we were taught them a week or two ago so I'm a lagging a little bit. I don't expect you guys to finish my homework for me, but if someone could point me in the right direction and give me a sample or an idea of what to do, I would greatly appreciate it. Thanks, Adam.
#include <string>
#include <iostream>
using namespace std;
struct Student
{
string name;
string address;
string city;
string state;
int zip;
char gender;
int id;
float gpa;
};
void printData(Student& x)
{
cout << "Name=" << x.name << ", Address=" << x.address << ", City=" << x.city << ", State=" << x.state << ", ZIP Code=" << x.zip << ", Gender=" << x.gender << ", Student ID=" << x.id << ", GPA=" << x.gpa << endl;
}
int main()
{
Student a;
Student b;
Student c;
cout << "I need the following information for all 3 students " << endl;
cout << "Name: " ;
getline(cin, a.name);
cout << "Address: ";
getline(cin, a.address);
cout << "City: ";
getline(cin, a.city);
cout << "State: ";
getline(cin, a.state);
cout << "ZIP Code: ";
cin >> a.zip;
cin.ignore(1000,10);
cout << "Gender [M] or [F]: ";
cin >> a.gender;
cin.ignore(1000,10);
cout << "ID Number: ";
cin >> a.id;
cin.ignore(1000,10);
cout << "GPA: ";
cin >> a.gpa;
cin.ignore(1000,10);
cout << endl;
cout << endl;
cout << "Name: " ;
getline(cin, b.name);
cout << "Address: ";
getline(cin, b.address);
cout << "City: ";
getline(cin, b.city);
cout << "State: ";
getline(cin, b.state);
cout << "ZIP Code: ";
cin >> b.zip;
cin.ignore(1000,10);
cout << "Gender [M] or [F]: ";
cin >> b.gender;
cin.ignore(1000,10);
cout << "ID Number: ";
cin >> b.id;
cin.ignore(1000,10);
cout << "GPA: ";
cin >> b.gpa;
cin.ignore(1000,10);
cout << endl;
cout << endl;
cout << "Name: " ;
getline(cin, c.name);
cout << "Address: ";
getline(cin, c.address);
cout << "City: ";
getline(cin, c.city);
cout << "State: ";
getline(cin, c.state);
cout << "ZIP Code: ";
cin >> c.zip;
cin.ignore(1000,10);
cout << "Gender [M] or [F]: ";
cin >> c.gender;
cin.ignore(1000,10);
cout << "ID Number: ";
cin >> c.id;
cin.ignore(1000,10);
cout << "GPA: ";
cin >> c.gpa;
cin.ignore(1000,10);
cout << endl;
cout << endl;
printData(a);
cout << endl;
printData(b);
cout << endl;
printData(c);
return 0;
}
1 1336
Hi Adam,
This may satisfy your need.
Regards,
M.Sivadhas.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PB |
last post by:
i have a class called school.java and i cant figure out how to construct
another class called course.java that adds 2 people to a course. Can anyone
help me out on how to set up constructors and...
|
by: BT |
last post by:
Ok, for a school assignment we have to use a pointer for an array of
ints, intstead of the usual X way, it compiles fine but when i run
it I am getting a seg fault that i can't figure out how to...
|
by: Ryan Kaskel |
last post by:
Hi! I am new to this newsgroup and need help implementing a hash table.
This assignment is for school but only concerns one method. Basically we
have to write methods like put(), get(),...
|
by: pretear_yuki |
last post by:
I'm a 14 year old student in Singapore. I am doing a programming for my Research Studies in school, I got the source codes of my programme from my mentor in the National University of Singapore...
|
by: genestarwing |
last post by:
QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it...
|
by: n355a |
last post by:
hi everyone....if anyone has time...
can anyone help me with virtual functions...
I have class student, Graduate, Undergraduate. There's a printInfo() in each class, and the one in student is...
|
by: Lockwood |
last post by:
someone check out this program and tell me what im doing wrong please...every time i fix some errors i get even more than before (right now theres 10). note that im a beginner/noob, and that this...
|
by: sallyk07 |
last post by:
Modify the Student class so that each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the...
|
by: laila2ethan |
last post by:
Need someones help , I am having a very difficult time understanding parameters and functions, can someone help me answer these questions
1. Write a program that helps an elementary school student...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |