الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

خطأ في الكود

مغلق
بدأه طالب سي+ في 27 ديسمبر 2007 · 3 رد · 566 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
You are to write a class named PC to represent features of personal computers. The data members of the class and default values will be:


Data member	Description	Default value	   
name	name of the computer (string) 	"No Name"	   
speed	processor speed in gigahertz (double)	100.0	   
memory	memory size in megabytes (double)	512.0	   
disk	disk drive size in gigabytes (double)	  80.0	   
price 	price in riyals (double)	0.0	 

The class should include the following:
A default constructor that sets default values for all variables. 
An overloaded constructor with parameters.
One get function for each data member that returns the current value.
One set function that sets new values for all data members.
An overloaded operator -= which decreases a PC object’s price by a given double value.
An overloaded operator >> that reads in the values of the data members.
An overloaded operator << that will display the values of the data members. 

Using the PC class as the base class, you need to derive class Laptop for laptop computers that has additional data members screen and weight, both of type double.  screen will hold the diagonal dimension of the laptop's screen in inches and weight will be the weight of the laptop in pounds. 

The derived class should include the following:
A default constructor that sets default values for all variables. 
An overloaded constructor with parameters.
One get function for each data member that returns the current value.
One set function that sets new values for all data members.
An overloaded operator >> that reads in the values of the data members.
An overloaded operator << that will display the values of the data members. 

Write a driver program that declares a dynamic array of laptops, inputs laptops’ information and finally provides the following two options: 
Display the data of all laptops.
Display the data for laptops with a price that lies within a specific range, thus with this option, you will ask the user to input the range. 

Notes: 
You are not going to use all member functions in the driver program. However, you should test them all (you do not need to submit the test).
You should read the size of the dynamic array and the laptops’ information from a file.
You should use separate files for the interface and implementation so that the implementation can be compiled separately from the application program.

#ifndef PC_H
#define PC_H

#include<string>

class PC
{
public:
	PC();
	PC(string the_name,double the_speed,double the_memory,double the_disk,double the_price);
	void set_name(string the_name, double the_speed, double the_memory, double the_disk, double the_price);
	double get_name();
	friend void operator*=( PC&first,const PC&second);

private:
	string name;
	double speed, memory, disk, price;

};
#endif

#include"PC.h"
#include<iostream>
using namespace std;

PC::PC()
{
		name="no name":
		speed=100.0;
		memory=512.0;
		disk=50.0;
		price=0.0;

}
PC::PC(string the_name,double the_speed,double the_memory,double the_disk,double the_price)
{

		name=the_name;
		speed=the_speed;
		memory=the_memory;
		disk=the_disk;
		price=the_price;
}
void PC::set-name(string the_name,double the_speed,double the_memory,double the_disk,double the_price)
{

		name=the_name;
		speed=the_speed;
		memory=the_memory;
		disk=the_disk;
		price=the_price;
}

}
double PC::get_name()
{

		return name;
		return speed;
		return memory;
		return disk;
		return price;



}
void PC::operator *=( PC first,const PC second)
{
return PC first *= PC second;

}

#include"PC.h"

int main()
{
	PC p1,p2;
	p1.get();
	p2.get();
	p1.set();
	p2.set();

	return 0;
}

#include"PC.h"

int main()
{
	PC p1,p2;
	p1.get();
	p2.get();
	p1.set();
	p2.set();

	return 0;
}

#include<iostream>
using namespace std;
#include"PDAs.h"

	PDAs::PDAs():PC(),color("no nmae yet"),weight(0)
	{
	}
	PDAs::PDAs(string the_color,string the_name,double the_speed,double the_memory,double the_disk,double the_price):PC(string the_name,double the_speed,double the_memory,double the_disk, double the_price),color(  the_color),weight(  the_weight)
	{
	}
	friend istream&operator>>(istream&ins,PDAs the_PDAs)
	{

			ins>>the_PDAs.color;
			ins>>the_PDAs.weight;
			return(ins);
	}
	friend ostream&operator<<(ostream&outs,const PDAs the_PDAs)
	{

			outs<<the_PDAs.color;
			outs<<the_PDAs.weight;
			return(outs);

	}

#ifndef PDAs_H
#define PDAs_h

#include"PC.h"

class PDAs:public PC
{
public:
	PDAs();
	PDAs(string the_color,string the_name,double the_speed,double the_memory,double the_disk,double the_price);
	friend istream&operator>>(istream&ins,PDAs the_PDAs);
	friend ostream&operator<<(ostream&outs,const PDAs the_PDAs);

private:
	string color;
	double weight;
};
#endif

#include"PDAc.h"
#include<iostream>
using namespace std;
int main()
{

		PDAs *c;
	   int maxx;
	   string color;
	   double weight,max;
	   cout<<"Enter the maxx\n":
	   cin>>maxx;
	   c=new PDAs[max];

	   for(i-0;i<maxx;i++)
	   cout<<"enter the color";
	   cin>>color;
	   (*PDAS).set_color[color];
		cout<<"Enter the weight":
		cin>>weight;
		(*PDAs).set_weight[weight];
}
 max=(*PDAs[0]).get_color[color];
count=i;
for(i=0;i<max;i++)
{cout<<"enter"<<max<<(count+1)<<(*PDAs[count]).get_weight[weight]<<endl;
cout<<"this"<<(*PDAs).get_color[color]<<(*PDAs).get_weight[weight];

}

هذا سؤال حاولات احلها بس شكا في حلي ومحتاجته الي يعرف الله يسعده يساعدني

تم تعديل هذه المشاركة بواسطة Khaled.Alshaya في 28 ديسمبر 2007 في 14:55

#2

الأن وش السؤال :wacko:

عل فكرة أنا مبتدا ب C++

لعلي أقدر أساعدك :)

تحياااااتي

للصداقة البرمجية

pro-vb6@hotmail.com

#3
//pc.h
#include <string>
using namespace std;

#ifndef PC_H
#define PC_H

class PC
{
public:

	PC();
	PC( string new_name, double new_speed, double new_memory, double new_disk, double new_price );
	string get_name();
	double get_speed();
	double get_memory();
	double get_disk();
	double get_price();
	void set_name(string new_name);
	void set_speed(double new_speed);
	void set_memory(double new_memory);
	void set_disk(double new_disk);
	void set_price (double new_price);
	friend void operator-=(PC& p_1, const double x);
	friend istream& operator >>(istream& ins, PC& P);
	friend ostream& operator <<(ostream& outs, const PC& p);

private: 

	string name;
	double speed, memory ,disk ,price;
};
#endif
+++++++++++++++++++++++++++++++++++++++++++++++++++++
//pc.cpp
#include <iostream>
using namespace std;
#include <string>
#include "PC.h"

PC::PC()
{ 
	name = "new_name";
	speed = 100.0;
	memory = 512.0;
	disk = 80.0;
	price  = 0.0;
}

PC::PC(string new_name, double new_speed, double new_memory, double new_disk, double new_price)
{ 
	name = new_name;
	speed = new_speed;
	memory = new_memory;
	disk = new_disk;
	price  = new_price;
}

string PC::get_name()
{
	return name;
}

double PC::get_speed()
{
	return speed;
}

double PC::get_memory()
{
	return memory;
}

double PC::get_disk()
{
	return disk;
}

double PC::get_price()
{
	return price;
}

void PC::set_name(string new_name)
{
	name = new_name;
}

void PC::set_speed(double new_speed)
{
	speed = new_speed;
}

void PC::set_memory(double new_memory)
{
	memory = new_memory;
}

void PC::set_disk(double new_disk) 
{	
	disk = new_disk;
}

void PC::set_price(double new_price)
{
	price = new_price;
}


void operator-=( PC& p, const double first )
{
	p.price -= first;
}

istream& operator>>( istream& ins, PC& p1 )
{
	ins >> p1.name;
	ins >> p1.speed;
	ins >> p1.memory;
	ins >> p1.disk;
	ins >> p1.price;

	return ins;
}

ostream& operator<<( ostream& outs, const PC& p1 )
{
	outs << " Name" << p1.name << endl;
	outs << " Speed" << p1.speed << endl;
	outs << " Memory" << p1.memory << endl;
	outs << " Disk" << p1.disk << endl;
	outs << " Price" << p1.price << endl;

	return outs;
}
++++++++++++++++++++++++++++++++++++++++++++++++++
//laptop.h
#include <iostream>
#include "PC.h"


#ifndef Laptop_H
#define Laptop_H

class Laptop : public PC
{
public:

	Laptop ();
	Laptop (string new_name, double new_speed, double new_memory, double new_disk, double new_price, double new_screen, double new_weight);
	double get_screen();
	double get_weight();
	void set_screen(double new_screen);
	void set_weight(double new_weight); 
	friend istream&operator>>(istream&ins, Laptop&L1);
	friend ostream&operator<<(ostream&outs, const Laptop&L1);

private:

	double screen;
	double weight;
};
#endif
+++++++++++++++++++++++++++++++++++++++++++++++++++
//laptop.cpp
#include <iostream>
using namespace std;
#include <string>
#include "Laptop.h"

Laptop::Laptop():PC()
{
	screen = 0;
	weight = 0;
}

Laptop::Laptop(string new_name, double new_speed, double new_memory, double new_disk, double new_price, double new_screen, 
double new_weight):PC(new_name, new_speed, new_memory, new_disk, new_price)

{
	screen = new_screen;
	weight = new_weight;
}

void Laptop::set(double new_screen, double new_weight)
{
	screen = new_screen;
	weight = new_weight;
}

istream&operator>>(istream&ins, Laptop&L1)
{
	ins >> L1.screen;
	ins >> L1.weight;

	return ins;
}

ostream&operator<<(ostream&outs, const Laptop&L1)
{
	outs << "  Screen  " << L1.screen << endl;
	outs << "  Weight  " << L1.weight << endl;

	return outs;
}

هذا محاولاتي بس انت مين مأعرفتها ممكن تشوفوها لي

#4

خلاص شكرا عرفت احلها

هذا الموضوع مغلق.

مواضيع مشابهة