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(Stude nt& 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 1346
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 such. Here is school.java
import java.text.DecimalFormat;
public class School
{...
|
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 fix. It
occurs at this line:
*d = rand() % 99 + 1
Here is the code for the first part of the program, the line that
causes the seg fault is
|
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(), expandCapacity(), etc. The hash
table is an array of pointer to HashNodes. Below is the header file for
the HashTable and HashNode classes:
> #ifndef...
|
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 Infocomm Research department. However, when I tried to compile the codes, I get the error message that says: "no matching function for call to...
|
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 occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of...
| |
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 made pure virtual. I had to create a vector of students that had a combination of Graduates and Undergraduates in main. Then I had to pass the vector...
|
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 doesnt work when i click run java application, either. im not sure what exactly i should put in the main method either...
import javax.swing.*;...
|
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 constructor such that each test score is assumed to initially be zero. Provide a method called setTestScore that accepts two parameters: the test number (1...
|
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 learn multiplication. Use rand to produce two positive one-digit integers. It should then type a question such as
How much is 6 times 7?...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |