It is not possible - the console decides how to handle user input. You would have to hook directly into the console to override its behavior, but there are am multitude of consoles/shells and not all allow this.
Thanks for the quick reply!
project requirements says get student Name and grades from the user and store them into array of object by calling the class member function.
here's my main ccp so far.
am I on the right track?
#include <iostream>
#include <string>
#include "Student.h"
usingnamespace std;
constint CAPACITY = 1000;
int main(){
int *numOfStudents;
numOfStudents = newint[CAPACITY];//points to an unknown number of students.Allocates memory of
//1000 array of type int and store the base address of array in numOfStudent.
cout << " Please enter the number of students " << ":";
cin >> *numOfStudents;
cout << "Please enter student data" << ":" <<endl;
//Student numOfStudents[CAPACITY];
string studentName;
int studentGrade = 0;
Student Student_1(&studentName, &studentGrade);
for (int i = 0; i < *numOfStudents; i++){
cout << "Name " << ": ";
cin >> studentName;
//cout << string(100, '\n');
cout << "Grade " << ":";
cin >> studentGrade;
}
cout << "Class Average " << ":";
for (int i = 0; i < *numOfStudents; i++){
Student_1.avgGrade();
cout << "Average Grade: " << Student_1.getGrade() << endl;
}
for (int i = 0; i < *numOfStudents; i++){
Student_1.gradeDistribution();
cout << "Grade Distribution: " << Student_1.getGrade() << endl;
}
system("pause");
return 0;
}
Well, I'd have to say no, because your requirements use the phrase "class member function" and your code has no classes. Check out the tutorials on this site if you think you missed a lecture: http://www.cplusplus.com/doc/tutorial/classes/
Oh, ok. I just quickly glanced at your code and didn't see any classes and assumed you hadn't made one, but you certainly did. Does it give you the correct output?
As I mentioned earlier, Name: and Grade should be printed next to each other.
is there a different way to get student Name and grades from the user and store them into array of object by calling the class member function?
As I already said, it isn't possible to have "Grade: " appear on the same line after the user types their name. 99% of consoles do not send input to your program until the user presses enter, and the user pressing enter goes to the next line. Remember, the user needs to be able to backspace.