Write a C++ program that will read user's full name into a C-string. User will enter first name followed by one or more spaces and then the last name. Also, obtain user's student ID also into a C-string. Pass the name and ID obtained along with another C-string to a function which will generate user name for campus computers from the full name and student ID into the third string parameter. the ID will be made up of the first two letters of the first name, followed by the first two letters of the last name, followed by the last 5 digits of the student ID. In main, print the user full name (fist name followed by one space and then the last name) and the user ID.

i dont know how to pass the name and id into the function.


this is my program so far:

#include <iostream>
#include <cstring>
using namespace std;

int main ()
{

	char fullname [50];
	char id [20];


	cout << "Enter student fullname: ";
		cin >> fullname;

		cout << "Enter student's id:";
		cin.getline ( id, 20, '\n' ); 
			cin.get();



		system ("pause");
			return 0;

}

Recommended Answers

All 2 Replies

Passing the strings to a function is no different than passing arrays of any other type. They are, after all, just arrays.

So a function prototype for you might be something like

void make_user_id( char name[], char id[], char user_id[] )

Note also that your code to read in the user's name will only get the first name. You need to use getline for this as well.

Val

>>User will enter first name followed by one or more spaces and then the last name

You can not do that with cin >> fullname; because cin will stop reading from the keyboard at the first space, which is not what you want. User getline() to change that behavior, like this: cin.getline(fullname, sizeof(fullname)); [edit]as vmanes said ^^^^[/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.