Hy Guys,I Need Your Help Regarding This Question..
I run this Program on Dev c++ and Compiler did not Show Error but During INput I can not input Name and Address in both student class and School Class..
Sorry For bad English.. :)

#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
class school{
    char name[50],address[50];
    int regdno,totalstudents;
public:
    void input()
    {

    cout<<endl<<endl<<endl;
    cout<<"<<<<<<<<--------Input School Information--------->>>>>>>>>";
    cout<<endl<<endl<<endl;


    cout<<"Enter Regd.No Of school : ";
    cin>>regdno;
    cout<<"Enter Name Of school : ";
    cin.getline(name,50);
    cout<<"Enter Address Of school : ";
    cin.getline(address,50);
    cout<<"Enter Total No.of Students in School : ";
    cin>>totalstudents;
    }
    void output()
    {
        cout<<endl<<endl<<endl;
        cout<<"<<<<<<<<--------School Information--------->>>>>>>>>";
        cout<<endl<<endl<<endl;
        cout<<"Name                        :      "<<name<<endl;
        cout<<"Address                     :      "<<address<<endl;
        cout<<"Redg.No                     :      "<<regdno<<endl;
        cout<<"Total No Of Students        :      "<<totalstudents<<endl;
    }
   // ~ ool();
};
class student          //:public  ool
{
    char name[50],fname[50],address[50];
    int rollno;
    long long contactno;
public:
/*  student()
    {
        name=NULL;
        fname=NULL;
        address=NULL;
        rollno=0;
        contactno=0;
    }*/
    void studentinput()
    {
        cout<<endl<<endl<<endl;
        cout<<"<<<<<<<<--------Input Student Information--------->>>>>>>>>";
        cout<<endl<<endl<<endl;


        char arr[50];
        cout<<"Enter Name Of Student : ";
        cin.getline(name,50);
        cout<<"Enter Father Name : ";
        cin.getline(fname,50);
        cout<<"Enter Roll NO Of Student : ";
        cin>>rollno;
        cout<<"Enter Address Of Student : ";
        cin.getline(address,50);
        cout<<"Enter Contact No Of Student : ";
        cin>>contactno;
    }
    void studentoutput()
    {
        cout<<endl<<endl<<endl;
        cout<<"<<<<<<<<--------Student Information--------->>>>>>>>>";
        cout<<endl<<endl<<endl;
        cout<<"Name           :      "<< name<<endl;
        cout<<"Father Name    :      "<< fname<<endl;
        cout<<"Roll No        :      "<< rollno<<endl;
        cout<<"Address        :      "<< address<<endl;
        cout<<"Contact No     :      "<< contactno<<endl;
    }   
};
int main()
{
    int repeat;
    student st;
    school sc;
    sc.input();
    st.studentinput();
    st.studentoutput();
    sc.output();
    system("pause");
}

Recommended Answers

All 2 Replies

whats the problem its seem like your code has no error , what input you want.
If you want recursively calling back in taking input in student then after complete the student info input place a choice option to make this input again .

Hello,
To start with, you are coding in C++, so use #include <string> instead of #include <string.h> which is old and several compiler might not include those header sooner or later. Then use string, instead of char arrays, since you have to keep us with the array size. It is probaly easiler in C++ to use string.

Secondly, you are having that issue of not been able to input your input Name and Address in both student class and School Class because just before getting those variables you still have \n in your input stream, which cin.getline(name, 50) and cin.getline(address, 50) in line 20, 61 and 67 read in.

There are several ways to solve this, but one of which is to use cin.get() before those lines. Don't forget that the issue is still occuring in line 24 too!

Lastly, if you must use cstring in your c++ code then, you might want to #include <cstring>.
Hope this helps.

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.