我需要帮助:“"< [英] i need help:""<

查看:95
本文介绍了我需要帮助:“"<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,

我有cs任务我试图解决它但我还有很多

错误,plzz帮助mee:"<它不是作弊becuz我试过&写了

前卫。我只想你告诉我我的错误


#these是操作

[a,b] + [c,d] = [a + c ,b + d],

[a,b] - [c,d] = [ad,bc],

[a,b] * [c,d ] = [min(ac,ad,bc,bd),max(ac,ad,bc,bd)],

1 / [a,b] = [1 / b,1 / a ]只有0不在[a,b]中。


&问题是将具有较低和较高

的类间隔写为数据成员,set,get,print和构造函数作为成员

函数。该类还有四个成员函数add,subtract,

乘以和除。


实现类成员,并编写一个声明两个的驱动程序

类间隔的对象,并在两个声明的对象上打印四个

操作的结果。


样本输入/输出:


输入第一个间隔的下限和上限:2 8

[2,8]

输入下限和第二个区间的上限:3 6

[3,6]


两个区间的总和是:[5,14]


两个区间的减法是:[ - 4,5]


两个区间的乘法是:[6,48]


第一个间隔的倒数是:[0.5,0.125]


这是我的编程


#include< iostream>

#include< string>


使用命名空间std;


班级间隔

{

int lower;

int upper;

void set(int,int)const;

void get(int,int) ;

void print();

void addtion(int,int,int,int);

void subtract(int,int,int ,int);

void mutiplty(int,int,int,int);

void divide(int,int,int,int);

};


int main()

{

区间优先,秒;

int l,u;


cout<<"输入第一个间隔的下限和上限;

cin>>首先。 l>> first.u;

cout<< endl;

cout<<" ["<<< first.l<<" ;,"<<<<<<<<<<<""<<< endl;

first.set(l,u);

cout<<<"输入第二个

区间的下限和上限" ;;

cin>> second.l>> second.u;

cout<< endl;

cout<<" ["<<< second.l<<"""<<< second.u<<"]"<< endl;


second.set(l,u);

print();


返回0;

}


void interval :: set(int,int)const

{

lower = l;

upper = u;

}

void interval: :get(int,int)

{

lower = l;

upper = u;

}

void interval :: addtion(int,int,int,int)

{int add1,add2;


add1 = first .l + second.l;

add2 = first.u + second.u;

}

void interval :: subtract(int, int,int,int)

{

int sub1,sub2;

sub1 = first.l-second.u;

sub2 = first.u-second.l;

}

void interval :: mutiplty(int,int,int,int);

{

int ac,ad,bc,bd,mul1,mul2;


ac = first.l * second.l;

ad = first.l * second.u;

bc = first.u * second.l;

bd = first.u * second。你好;


mul1 = min(ac,ad,bc,bd);

mul2 = ma x(ac,ad,bc,bd);

}

void divide(int,int,int,int);

{

int d1,d2;


if(first.l == 0&& first.u == 0)

cout<<" error"<< endl;

else

d1 = 1 / first.l;

d2 = 1 /first.u;

}

void print();

{

cout<<""两个区间的总和是:

["<< add1<<"""<< add2<<""]"<<< endl ;

cout<<"两个区间的减法是:

["<<<<<"""<<< ; sub2<<"]"<< endl;

cout<<"两个区间的重复数据是:

["< ;< MUL1<<","<< MUL2<<"]"<< ENDL;

COUT<<"所述第一的倒数间隔是:

["<<<<<<<<<<","<<< d2<<"""<<< endl;

}

解决方案

" CuTe_Engineer"写道:


我有cs任务我试图解决它,但我还有很多

错误,plzz帮助mee:"<它不是作弊becuz我试过&写了

前卫。我只想你告诉我我的错误


#these是操作

[a,b] + [c,d] = [a + c ,b + d],

[a,b] - [c,d] = [ad,bc],

[a,b] * [c,d ] = [min(ac,ad,bc,bd),max(ac,ad,bc,bd)],

1 / [a,b] = [1 / b,1 / a ]只有0不在[a,b]中。


&问题是将具有较低和较高

的类间隔写为数据成员,set,get,print和构造函数作为成员

函数。该类还有四个成员函数add,subtract,

乘以和除。


实现类成员,并编写一个声明两个的驱动程序

类间隔的对象,并在两个声明的对象上打印四个

操作的结果。


样本输入/输出:


输入第一个间隔的下限和上限:2 8

[2,8]


输入第二个区间的下限和上限:3 6

[3,6]


两个区间的总和为:[5, 14]

两个区间的减法是:[ - 4],


两个区间的乘法是:[6 ,48]


第一个间隔的倒数是:[0.5,0.125]


这是我的编程


#include< iostream>

#include< string>


使用命名空间std;


班级间隔

{

int lower;

int upper;



私人:


这是我注意到的第一个错误。缺乏使函数变得私有。


void set(int,int)const;

void get(int,int);

void print();

void addtion(int,int,int,int);

void subtract(int,int,int,int) ;

void mutiplty(int,int,int,int);

void divide(int,int,int,int);

} ;


int main()

{

区间第一,第二;

int l, u;


cout<<"输入第一个间隔的下限和上限;

cin>> first.l>> ; first.u;

cout<< endl;

cout<<" ["<<< first.l<<""," ;<<<<<<<"]"<< endl;

first.set(l,u);

cout<< ;输入第二个

区间的下限和上限;

cin>> second.l>> second.u;

cout<< endl;

cout&l t;<" ["<< second.l<<"""<< second.u<<"""<<< endl;


second.set(l,u);

print();


返回0;

}


void interval :: set(int,int)const

{

lower = l;

upper = u;

}

void interval :: get(int,int)

{

lower = l;

upper = u;

}

void interval :: addtion(int,int,int,int)

{int add1,add2;


add1 = first.l + second.l;

add2 = first.u + second .u;

}

void interval :: subtract(int,int,int,int)

{

int sub1,sub2;

sub1 = first.l-second.u;

sub2 = first.u-second.l;

}

void interval :: mutiplty(int,int,int,int);

{

int ac,ad,bc,bd, mul1,mul2;


ac = first.l * second.l;

ad = first.l * second.u;

bc = first.u * second.l;

bd = first.u * second.u;


mul1 = min(ac,ad,bc,bd);

mul2 = max(ac,ad,bc,bd);

}

void divide(int,int,int,int);

{

int d1,d2;


if(first.l == 0&& first.u == 0)

cout<<" error"<< endl;

else

d1 = 1 / first.l;

d2 = 1 / first.u;

}

void print();

{

cout<< ;两个间隔的总和是:

["<<<<<<<<<<<<<<<<""<<< add2<<""""< < endl;

cout<<"两个间隔的减法是:

["<<< sub1<<"""" << sub2<<"]"<< endl;

cout<<"两个区间的重复数据是:

[ "<< MUL1<<","<< MUL2<<"]"<< ENDL;

COUT<<"该reciproc第一个间隔的al是:

["<<<<<<<<<""<<< d2<<""""<<<< endl;

}



2007-09-14 15:06,CuTe_Engineer写道:
< blockquote class =post_quotes>
hii,

i有cs任务我试图解决它但我还有很多

错误,plzz帮助mee:" <它不是作弊becuz我试过&写了

前卫。我只想你告诉我我的错误


#these是操作

[a,b] + [c,d] = [a + c ,b + d],

[a,b] - [c,d] = [ad,bc],

[a,b] * [c,d ] = [min(ac,ad,bc,bd),max(ac,ad,bc,bd)],

1 / [a,b] = [1 / b,1 / a ]只有0不在[a,b]中。


&问题是将具有较低和较高

的类间隔写为数据成员,set,get,print和构造函数作为成员

函数。该类还有四个成员函数add,subtract,

乘以和除。


实现类成员,并编写一个声明两个的驱动程序

类间隔的对象,并在两个声明的对象上打印四个

操作的结果。


样本输入/输出:


输入第一个间隔的下限和上限:2 8

[2,8]


输入第二个区间的下限和上限:3 6

[3,6]


两个区间的总和为:[5, 14]

两个区间的减法是:[ - 4],


两个区间的乘法是:[6 ,48]


第一个间隔的倒数是:[0.5,0.125]


这是我的编程


#include< iostream>

#include< string>


使用命名空间std;


班级间隔

{

int lower;

int upper;



public:

interval(int l,int u);


不要忘记构造函数。


void set(int,int)const;



不是const,请参阅下面的解释。


void get(int,int);



无效,见下文。


void print();



void print()const;


void addtion(int,int,int,int);



void add(const interval&)const;


void subtract(int,int,int, INT);



void subtract(const interval&)const;


void mutiplty(int,int,int, INT);



void multiply(const interval&)const;


void divide(int,int,int, INT);



void divide(const interval&)const;


};


int main()

{

区间第一,第二;



删除那些,你(现在)有一个构造函数,确保也使用它。


int l,u;


cout<<"输入第一个间隔的下限和上限;



cin> l> u;


interval first(l,u);


cout<<" ["<<< first.l<<"""<<< first.u<<"]"< ;< endl;

first.set(l,u);



不! 1)他们被称为低级和高级,而不是l和u,2)他们是私人的b $ b,除非通过使用会员

函数,否则你永远不应该改变它们,3你应该使用print()来显示它们的价值。

同样适用于第二个。


print();



print()是会员,您需要一个对象来调用它。


>

返回0;

}



interval :: interval(int l,int u)

{

//在此处插入代码,除非您知道

中的初始化列表//您应该使用它们。

}


void interval :: set(int,int)const



这里不能使用const,它表示此函数不会对对象进行任何更改。这显然是。


{

lower = l;

upper = u;

}

void interval :: get(int,int)



不,这不起作用,您需要将它们作为引用传递,或者返回包含其值的

结构或生成get_upper()和get_lower()

功能。


void interval :: addtion(int,int,int,int)



你应该传递另一个间隔作为参数


void interval :: addition(const interval&)const


{int add1,add2;

add1 = first.l + second.l;

add2 = first.u + second.u;

}



你应该使用构造函数来创建新对象。

其他函数也是如此。


void print();



void interval :: print()const


{

cout< ;<"两个间隔的总和是:

["<<<<<<<<<<<<""<<< add2<<""""" << endl;

cout<<"两个区间的减法是:

["<<< sub1<<""" "<<<<<<<"""<< endl;

cout<<"两个区间的重复数据是:

["<< MUL1<<","<< MUL2<<"]"<< ENDL;

COUT<<"第一个区间的倒数是:

["<<< d1<<"""<<< d2<<""""<<< endl ;

}



什么是add1和add2?所有这些操作都应该在

main()中执行,它应该看起来像


cout<< 两个区间的总和是:" ;;

(第一个+第二个).print();


我希望你还有很长的时间直到你需要转换

中的作业,因为你在课程中显然没有注意到

(或者你的导师真的很糟糕)。


-

Erik Wikstr?m




9月14日,8日:47 pm,Eri​​k Wikstr?m< Erik-wikst ... @ telia.comwrote:


2007-09-14 15:06,CuTe_Engineer写道:



hii,

i有cs赋值我试图解决它但我还有很多

错误,plzz帮助mee:"<它不是作弊becuz我试过&写了

前卫。我只想你告诉我我的错误


#these是操作

[a,b] + [c ,d] = [a + c,b + d],

[a,b] - [c,d] = [ad,bc],

[a ,b] * [c,d] = [min(ac,ad,bc,bd),max(ac,ad,bc,bd)],

1 / [a,b] = [1 / b,1 / a]仅当0不在[a,b]中时。


&问题是将具有较低和较高

的类间隔写为数据成员,set,get,print和构造函数作为成员

函数。该类还有四个成员函数add,subtract,

乘以及除。


实现类成员,并编写一个驱动程序,声明类间隔的两个

对象并打印结果两个声明对象上的四个
操作。


样本输入/输出:


输入下限和上限第一个间隔的限制:2 8

[2,8]


输入第二个间隔的下限和上限间隔:3 6

[3,6]


两个区间的总和是:[5,14]


两个区间的减法是:[ - 4],


两个区间的乘法是:[6,48]


第一个区间的倒数是:[0.5,0.125]


这是我的前卫


#include< iostream>

#i nclude<串GT;


using namespace std;


class interval

{

int lower;

int upper;



public:

interval(int l,int u);


不要忘记构造函数。


void set(int,int)const;



不是const,请参阅下面的解释。


void get(int,int);



无效,见下文。


void print();



void print()const;


void addtion(int,int,int,int);



void add(const interval&)const;


void subtract(int,int,int, INT);



void subtract(const interval&)const;


void mutiplty(int,int,int, INT);



void multiply(const interval&)const;


void divide(int,int,int, INT);



void divide(const interval&)const;


};


int main()

{

interval first,second;



删除那些,你(现在)有一个构造函数,确保也使用它。


int l,u;


cout<<"输入第一个间隔的下限和上限;



cin> l> u;


interval first(l,u);


cout<<" ["<<< first.l<<"""<<< first.u<<"]"< ;< endl;

first.set(l,u);



不! 1)他们被称为低级和高级,而不是l和u,2)他们是私人的b $ b,除非通过使用会员

函数,否则你永远不应该改变它们,3你应该使用print()来显示它们的价值。

同样适用于第二个。


print();



print()是一个成员,你需要一个对象来调用它。


return 0;

}



interval :: interval(int l,int u)

{

//在这里插入代码,除非你知道

中的初始化列表//你应该使用它们。


}


void interval :: set(int,int)const



这里不能使用const,它表明这个函数没有不要对对象进行任何改变

,这显然是。


{

lower = l;

upper = u;

}

void interval :: get(int,int)



不,这不起作用,你需要将它们作为引用传递,或者返回包含它们的值的

结构或者使get_upper()和get_lower()

函数。

void interval :: addtion(int,int,int,int)



你应该传递另一个间隔作为参数


void interval :: addition(const interval&)const


{int add1,add2;


add1 = first.l + second.l;

add2 = first.u + second.u;

}



你应该使用构造函数来创建新对象。

其余部分也是如此函数。


void print();



void interval :: print()const


{

cout< ;<"两个间隔的总和是:

["<<<<<<<<<<<<""<<< add2<<""""" << endl;

cout<<"两个区间的减法是:

["<<< sub1<<""" "<<<<<<<"""<< endl;

cout<<"两个区间的重复数据是:

["<< MUL1<<","<< MUL2<<"]"<< ENDL;

COUT<<"第一个区间的倒数是:

["<<< d1<<"""<<< d2<<""""<<< endl ;

}



什么是add1和add2?所有这些操作都应该在

main()中执行,它应该看起来像


cout<< 两个区间的总和是:" ;;

(第一个+第二个).print();


我希望你还有很长的时间直到你需要转换

中的作业,因为你在课程中显然没有注意到

(或者你的导师真的很糟糕)。


-

Erik Wikstr?m-隐藏引用文字 -


- 显示引用文字 -



Erik感谢你帮助我,因为我老师的方式太棒了。

不是*真的很糟糕我喜欢他但是可能有一些问题< br $> b $ b我loOol


好​​了我现在理解你的解释但不是everthing:"

你能告诉我如何使用的例子构造函数&我们应该什么时候使用它?b $ b?我相信它用于为

类中的成员赋值..


void interval :: addition(const interval&)const


>


{int add1,add2;


add1 = first.l + second.l;

add2 = first.u + second.u;

}



你应该使用构造函数来创建新对象。

其余部分也是如此函数。(你能告诉我怎么知道如何使用constuctor *)


void interval :: print()const


{

cout<<"两个区间的总和是:

["<< ; add1<<<","<<< add2<<"]"<< endl;

cout<<"两个间隔的减法是:

["<<<<<<<<<","<<<<<<""""<< endl;

COUT<<"所述两个间隔的mutiplication是:

["<< MUL1<<","<< MUL2<<" ]"< < endl;

cout<<"第一个间隔的倒数是:

["<<< d1<<"""" <<<<<"]"<<< endl;

}



什么是add1和add2 ?所有这些操作都应该在

main()中执行,它应该看起来像


cout<< 两个区间的总和是:;

(第一个+第二个).print();



如果我在主要部分写下所有这些,那么我应该写什么?

打印!!!

对不起,我知道我很讨厌你:"


thhhhhhhhhaaaaaaaaaank你非常想帮助我

i应该在星期四提交我的作业我还有5天它很好:)


hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes

#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].

& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.

Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.

Sample input / output:

Enter the lower and upper limits of the first interval: 2 8
[2, 8]
Enter the lower and upper limits of the second interval: 3 6
[3, 6]

The sum of the two intervals is: [5, 14]

The subtraction of the two intervals is: [-4, 5]

The multiplication of the two intervals is: [6, 48]

The reciprocal of the first interval is: [0.5, 0.125]

this is my prog

#include<iostream>
#include<string>

using namespace std;

class interval
{
int lower;
int upper;
void set(int,int)const;
void get (int,int);
void print();
void addtion(int,int,int,int);
void subtract(int,int,int,int);
void mutiplty(int,int,int,int);
void divide(int,int,int,int);
};

int main()
{
interval first,second;
int l,u;

cout<<"Enter the lower and the upper limits of the first interval";
cin>>first.l>>first.u;
cout<<endl;
cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second
interval";
cin>>second.l>>second.u;
cout<<endl;
cout<<"["<<second.l<<","<<second.u<<"]"<<endl;

second.set(l,u);
print();

return 0;
}

void interval::set(int,int)const
{
lower=l;
upper=u;
}
void interval::get(int,int)
{
lower=l;
upper=u;
}
void interval::addtion(int,int,int,int)
{ int add1,add2;

add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(int,int,int,int)
{
int sub1,sub2;
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(int,int,int,int);
{
int ac,ad,bc,bd,mul1,mul2;

ac=first.l*second.l;
ad=first.l*second.u;
bc=first.u*second.l;
bd=first.u*second.u;

mul1=min(ac,ad,bc,bd);
mul2=max(ac,ad,bc,bd);
}
void divide(int,int,int,int);
{
int d1,d2;

if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void print();
{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}

解决方案

"CuTe_Engineer" writes:

i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes

#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].

& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.

Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.

Sample input / output:

Enter the lower and upper limits of the first interval: 2 8
[2, 8]
Enter the lower and upper limits of the second interval: 3 6
[3, 6]

The sum of the two intervals is: [5, 14]

The subtraction of the two intervals is: [-4, 5]

The multiplication of the two intervals is: [6, 48]

The reciprocal of the first interval is: [0.5, 0.125]

this is my prog

#include<iostream>
#include<string>

using namespace std;

class interval
{
int lower;
int upper;

Private:

That''s the first error I note. The lack makes the functions private.

void set(int,int)const;
void get (int,int);
void print();
void addtion(int,int,int,int);
void subtract(int,int,int,int);
void mutiplty(int,int,int,int);
void divide(int,int,int,int);
};

int main()
{
interval first,second;
int l,u;

cout<<"Enter the lower and the upper limits of the first interval";
cin>>first.l>>first.u;
cout<<endl;
cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);
cout<<"Enter the lower and the upper limits of the second
interval";
cin>>second.l>>second.u;
cout<<endl;
cout<<"["<<second.l<<","<<second.u<<"]"<<endl;

second.set(l,u);
print();

return 0;
}

void interval::set(int,int)const
{
lower=l;
upper=u;
}
void interval::get(int,int)
{
lower=l;
upper=u;
}
void interval::addtion(int,int,int,int)
{ int add1,add2;

add1=first.l+second.l;
add2=first.u+second.u;
}
void interval::subtract(int,int,int,int)
{
int sub1,sub2;
sub1=first.l-second.u;
sub2=first.u-second.l;
}
void interval::mutiplty(int,int,int,int);
{
int ac,ad,bc,bd,mul1,mul2;

ac=first.l*second.l;
ad=first.l*second.u;
bc=first.u*second.l;
bd=first.u*second.u;

mul1=min(ac,ad,bc,bd);
mul2=max(ac,ad,bc,bd);
}
void divide(int,int,int,int);
{
int d1,d2;

if(first.l==0&&first.u==0)
cout<<"error"<<endl;
else
d1=1/first.l;
d2=1/first.u;
}
void print();
{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}



On 2007-09-14 15:06, CuTe_Engineer wrote:

hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes

#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].

& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.

Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.

Sample input / output:

Enter the lower and upper limits of the first interval: 2 8
[2, 8]
Enter the lower and upper limits of the second interval: 3 6
[3, 6]

The sum of the two intervals is: [5, 14]

The subtraction of the two intervals is: [-4, 5]

The multiplication of the two intervals is: [6, 48]

The reciprocal of the first interval is: [0.5, 0.125]

this is my prog

#include<iostream>
#include<string>

using namespace std;

class interval
{
int lower;
int upper;

public:
interval(int l, int u);

Do not forget the constructor.

void set(int,int)const;

Not const, see below for explanation.

void get (int,int);

Will not work, see below.

void print();

void print() const;

void addtion(int,int,int,int);

void add(const interval&) const;

void subtract(int,int,int,int);

void subtract(const interval&) const;

void mutiplty(int,int,int,int);

void multiply(const interval&) const;

void divide(int,int,int,int);

void divide(const interval&) const;

};

int main()
{
interval first,second;

Remove those, you (now) have a constructor, make sure to also use it.

int l,u;

cout<<"Enter the lower and the upper limits of the first interval";

cin >l >u;

interval first(l, u);

cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);

No! 1) they are called lower and upper, not l and u, 2) they are
private, you should never change them unless through the usage of member
functions, 3) you should use print() to show their value.
Same goes for this the second one.

print();

print() is a member, you need an object to call it.

>
return 0;
}

interval::interval(int l, int u)
{
// Insert code here, unless you know about initialisation lists in
// which case you should use them.
}

void interval::set(int,int)const

Cannot use const here, it indicates that this function does not make any
changes to the object, which is obviously does.

{
lower=l;
upper=u;
}
void interval::get(int,int)

No, this does not work, you need to pass them as references, or return a
struct containing their values or make get_upper() and get_lower()
functions.

void interval::addtion(int,int,int,int)

You should pass another interval as parameters

void interval::addition(const interval&) const

{ int add1,add2;

add1=first.l+second.l;
add2=first.u+second.u;
}

And you should use the constructor to create the new object.
The same goes for the rest of the functions.

void print();

void interval::print() const

{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}

And what are add1 and add2? All those operations should be performed in
main() and it should look something like

cout << "The sum of the two intervals is: ";
(first + second).print();

I hope you have much time left until you need to turn the assignment in
because you have obviously not been paying attention during the lessons
(or your instructor is *really* bad).

--
Erik Wikstr?m



On Sep 14, 8:47 pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

On 2007-09-14 15:06, CuTe_Engineer wrote:


hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes

#these are the operations
[a, b] + [c, d] = [a+c, b+d],
[a, b] - [c, d] = [a-d, b-c],
[a, b] * [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)],
1/[a, b] = [1/b, 1/a] only if 0 not in [a,b].

& the Question is to Write the class interval that has lower and upper
as data members, set, get, print, and constructors as member
functions. The class also has the four member functions add, subtract,
multiply, and divide.

Implement the class members, and write a driver that declares two
objects of the class interval and prints the results of the four
operations on the two declared objects.

Sample input / output:

Enter the lower and upper limits of the first interval: 2 8
[2, 8]

Enter the lower and upper limits of the second interval: 3 6
[3, 6]

The sum of the two intervals is: [5, 14]

The subtraction of the two intervals is: [-4, 5]

The multiplication of the two intervals is: [6, 48]

The reciprocal of the first interval is: [0.5, 0.125]

this is my prog

#include<iostream>
#include<string>

using namespace std;

class interval
{
int lower;
int upper;


public:
interval(int l, int u);

Do not forget the constructor.

void set(int,int)const;


Not const, see below for explanation.

void get (int,int);


Will not work, see below.

void print();


void print() const;

void addtion(int,int,int,int);


void add(const interval&) const;

void subtract(int,int,int,int);


void subtract(const interval&) const;

void mutiplty(int,int,int,int);


void multiply(const interval&) const;

void divide(int,int,int,int);


void divide(const interval&) const;

};

int main()
{
interval first,second;


Remove those, you (now) have a constructor, make sure to also use it.

int l,u;

cout<<"Enter the lower and the upper limits of the first interval";


cin >l >u;

interval first(l, u);

cout<<"["<<first.l<<","<<first.u<<"]"<<endl;
first.set(l,u);


No! 1) they are called lower and upper, not l and u, 2) they are
private, you should never change them unless through the usage of member
functions, 3) you should use print() to show their value.
Same goes for this the second one.

print();


print() is a member, you need an object to call it.

return 0;
}


interval::interval(int l, int u)
{
// Insert code here, unless you know about initialisation lists in
// which case you should use them.

}

void interval::set(int,int)const


Cannot use const here, it indicates that this function does not make any
changes to the object, which is obviously does.

{
lower=l;
upper=u;
}
void interval::get(int,int)


No, this does not work, you need to pass them as references, or return a
struct containing their values or make get_upper() and get_lower()
functions.

void interval::addtion(int,int,int,int)


You should pass another interval as parameters

void interval::addition(const interval&) const

{ int add1,add2;

add1=first.l+second.l;
add2=first.u+second.u;
}


And you should use the constructor to create the new object.
The same goes for the rest of the functions.

void print();


void interval::print() const

{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}


And what are add1 and add2? All those operations should be performed in
main() and it should look something like

cout << "The sum of the two intervals is: ";
(first + second).print();

I hope you have much time left until you need to turn the assignment in
because you have obviously not been paying attention during the lessons
(or your instructor is *really* bad).

--
Erik Wikstr?m- Hide quoted text -

- Show quoted text -

Erik thanks for helping me you are soo kind by the way my teacher is
not *really* bad i like him but maybe there is some thing wrong with
me loOol

ok now i understood your explaination but not everthing :"
can you show me example of how to use the constructor & when should we
use it ? i believe it is used to assgin values to the members in
class ..

void interval::addition(const interval&) const

>

{ int add1,add2;

add1=first.l+second.l;
add2=first.u+second.u;
}


And you should use the constructor to create the new object.
The same goes for the rest of the functions.( can you show me how i don`tknow how to use constuctor*)

void interval::print() const

{
cout<<"The sum of the two intervals is:
[ "<<add1<<","<<add2<<"]"<<endl;
cout<<"The subtraction of the two intervals is:
[ "<<sub1<<","<<sub2<<"]"<<endl;
cout<<"The mutiplication of the two intervals is:
[ "<<mul1<<","<<mul2<<"]"<<endl;
cout<<"The reciprocal of the first interval is:
[ "<<d1<<","<<d2<<"]"<<endl;
}


And what are add1 and add2? All those operations should be performed in
main() and it should look something like

cout << "The sum of the two intervals is: ";
(first + second).print();

if i wrote all these in the main then what should i write in
print!!!
sorry i know that i`m annoying you :""

thhhhhhhhhaaaaaaaaaank you very much for helping me
i should submit my assign on thursday i still have 5 days it`s okey :)


这篇关于我需要帮助:“&quot;&lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆