Click here to Skip to main content
15,868,116 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
#include<iostream>
#include<conio.h>
using namespace std;
class student
{
	int id;
	float t1,t2,t3;
	char name[50];
	public:
		student()
		{
	}
	student(int a,int b,int c)
{
	t1=a;
	t2=b;
	t3=c;
}
student(student &t )
{
t1=t.t1;
t2=t.t2;
t3=t.t3;
}
void display();
void read();
};
void student::read()
{
	cout<<"enter the name"<<endl;
 cin="">>name;
	cout<<"enter the id"<<endl;
 cin="">>id;
	cout<<"enter the mark 1"<<endl;
 cin="">>t1;
	cout<<"enter the mark 2"<<endl;
 cin="">>t2;
	cout<<"enter the mark 3"<<endl;
 cin="">>t3;
}
void student::display()
{
	cout<<"the student values are";
	cout<<"the name"<<"="<


What I have tried:

the question of the program is
create a class student with data memebers id,name,mark using default,parametrized,copy constructor initialize the values of 3 student object.using the memeber function display() the values of all student object
Posted
Updated 18-Jun-22 8:20am
v4

No. Read the question - the full version that you were given, rather than the abstract you threw at us - and you will see that it requires you to create three instances, and fill them with data.

Testing your code is important - and it's part of your task here, not mine. If you don't learn how to do it now with trivial code like this, you will never learn how to do it properly ...
So give it try: read the question, work out exactly what it requires you do do, and test your code against that. If it fits the brief, submit it. If it doesn't, fix it!
 
Share this answer
 
A few things, by no means a complete analysis of all your code.

1. When you edited your question, you deleted the description of what the code is supposed to do.
2. The default constructor should initialize all fields to default values.
3. char name[50] is the C approach. In C++, use std::string[^]. The default constructor doesn't have to initialize std::string name, because string has a default constructor of its own that will initialize itself to an empty string.
4. A copy constructor should take a const argument: student(const student& that).
5. There should probably be a constructor that sets all fields, not just the three marks.
6. The display function is either incomplete or was only partly copy-pasted. After submitting a question, proof read it carefully and fix any errors.
 
Share this answer
 
v2
Comments
OriginalGriff 18-Jun-22 14:45pm    
I rolled it back - removing the homework assignment so his teacher didn't spot it, I suspect as that was the only change ...
Quote:
Is my code complete according to the question

Difficult to tell as there is no requirement in your question (v4).
Quote:
is this the output that the code should produce

As there is no sample output in the question, it is difficult to tell too.
Generally speaking, the fact that your code output match expected output is a good indication that your code is correct.
 
Share this answer
 
Comments
OriginalGriff 18-Jun-22 14:45pm    
I rolled it back - removing the homework assignment so his teacher didn't spot it, I suspect as that was the only change ...
Patrice T 18-Jun-22 15:56pm    
This let little chances for any help. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900