Click here to Skip to main content
15,896,154 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: wall message in windows Pin
David Crow24-Apr-08 10:36
David Crow24-Apr-08 10:36 
GeneralReading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
TheBlindWatchmaker13-Apr-08 17:46
TheBlindWatchmaker13-Apr-08 17:46 
GeneralRe: Reading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
enhzflep14-Apr-08 4:00
enhzflep14-Apr-08 4:00 
GeneralRe: Reading in 16 and 24-bit audio data into (32-bit) integer buffers Pin
TheBlindWatchmaker14-Apr-08 18:22
TheBlindWatchmaker14-Apr-08 18:22 
GeneralOpening Word with "Pen" selected instead of cursor Pin
goodoljosh198013-Apr-08 14:57
goodoljosh198013-Apr-08 14:57 
GeneralRe: Opening Word with "Pen" selected instead of cursor Pin
nisha0000013-Apr-08 19:08
nisha0000013-Apr-08 19:08 
GeneralRe: Opening Word with "Pen" selected instead of cursor Pin
goodoljosh198014-Apr-08 7:58
goodoljosh198014-Apr-08 7:58 
GeneralConvert array to pointers Pin
KARFER13-Apr-08 12:26
KARFER13-Apr-08 12:26 
Hello All

I have This Code [assignment] and I want the user to control over the maximum size of CSet.

using integer pointer instead of integer array and by constructor can specifies the desired size.

<br />
#include <iostream><br />
#include <conio.h><br />
using namespace std;<br />
<br />
const int maxCard = 100;<br />
<br />
class CSet <br />
{<br />
	private:<br />
		int elems[maxCard];<br />
		int card;<br />
<br />
	public:<br />
		CSet()<br />
		{<br />
			card = 0;<br />
<br />
			return;<br />
		}<br />
<br />
		bool Member (const int);<br />
		void AddElem (const int);<br />
		void RmvElem (const int);<br />
		void Copy (CSet &);<br />
		bool Equal (CSet &);<br />
		void intersect (CSet &,CSet &);<br />
		void Union (CSet &,CSet &);<br />
		void print ();<br />
<br />
};<br />
<br />
bool CSet::Member(const int elem)<br />
{<br />
	for (register int i = 0;i < card;++i)<br />
		if (elems[i] == elem)<br />
			return true;<br />
		<br />
	return false;<br />
}<br />
<br />
void CSet::AddElem(const int elem)<br />
{<br />
	if (Member(elem))<br />
		return;<br />
<br />
	if (card < maxCard)<br />
		elems[card++] = elem;<br />
	else<br />
		cout <<"Set Overflow"<<endl;<br />
}<br />
<br />
<br />
void CSet::RmvElem(const int elem)<br />
{<br />
	for (register int i = 0;i <card;++i)<br />
		if (elems[i] == elem)<br />
		{<br />
			for (;i<card - 1;++i)<br />
				elems[i] = elems[i + 1];<br />
<br />
			--card;<br />
		}<br />
}<br />
<br />
void CSet::Copy(CSet &set)<br />
{<br />
	for (register int i =0;i<card;++i)<br />
		set.elems[i] = elems[i];<br />
<br />
	set.card = card;<br />
<br />
	return;<br />
}<br />
<br />
bool CSet::Equal(CSet &set)<br />
{<br />
	if (card != set.card)<br />
		return false;<br />
<br />
	for (register int i = 0;i < card;++i)<br />
		if (!set.Member(elems[i]))<br />
			return false;<br />
<br />
	return true;<br />
}<br />
<br />
void CSet::intersect(CSet & set,CSet &res)<br />
{<br />
	res.card = 0;<br />
<br />
	for (register int i = 0;i <card;++i)<br />
		if (set.Member(elems[i]))<br />
			res.elems[res.card++] = elems[i];<br />
<br />
	return;<br />
}<br />
<br />
void CSet::Union(CSet &set,CSet &res)<br />
{<br />
	set.Copy(res);<br />
<br />
	for (register int i=0;i <card;++i)<br />
		res.AddElem(elems[i]);<br />
<br />
	return;<br />
}<br />
<br />
void CSet::print()<br />
{<br />
	cout <<"{";<br />
<br />
	for (int i=0;i<card-1;++i)<br />
		cout <<elems[i] <<",";<br />
<br />
	if (card > 0)<br />
		cout <<elems[card - 1];<br />
	cout <<"}\n";<br />
<br />
	return;<br />
}<br />
<br />
int main ()<br />
{<br />
	CSet s1,s2,s3;<br />
<br />
<br />
	s1.AddElem(10);<br />
	s1.AddElem(20);<br />
	s1.AddElem(30);<br />
	s1.AddElem(40);<br />
<br />
	s2.AddElem(30);<br />
	s2.AddElem(50);<br />
	s2.AddElem(10);<br />
	s2.AddElem(60);<br />
<br />
	cout <<"S1 = ";<br />
	s1.print();<br />
	<br />
	cout <<"\nS2 = ";<br />
	s2.print();<br />
	cout <<endl;<br />
<br />
	if (s1.Member(20))<br />
		cout <<"20 is in s1"<<endl;<br />
	<br />
	s1.intersect(s2,s3);<br />
		cout <<"s1 intersection s2=";<br />
	s3.print();<br />
<br />
	s1.Union(s2,s3);<br />
		cout <<"s1 union s2 = ";<br />
		s3.print();<br />
<br />
	if (!s1.Equal(s2))<br />
		cout <<"s1 !=s2"<<endl;<br />
<br />
	<br />
	getch ();<br />
	return 0;<br />
}<br />


Thank's For all


-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*

GeneralRe: Convert array to pointers Pin
GDavy13-Apr-08 22:18
GDavy13-Apr-08 22:18 
GeneralAudio Equalizer With and Without DirectSound(ParamEq DMO) Pin
Akin Ocal13-Apr-08 11:38
Akin Ocal13-Apr-08 11:38 
QuestionInitializing std::string with "Extended ASCII Codes" Pin
Mushtaque Nizamani13-Apr-08 9:34
Mushtaque Nizamani13-Apr-08 9:34 
GeneralRe: Initializing std::string with "Extended ASCII Codes" Pin
Randor 13-Apr-08 14:06
professional Randor 13-Apr-08 14:06 
GeneralRe: Initializing std::string with "Extended ASCII Codes" Pin
Mushtaque Nizamani13-Apr-08 16:05
Mushtaque Nizamani13-Apr-08 16:05 
GeneralNo hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr13-Apr-08 9:03
Larry Mills Sr13-Apr-08 9:03 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Michael Dunn13-Apr-08 12:59
sitebuilderMichael Dunn13-Apr-08 12:59 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 6:02
Larry Mills Sr14-Apr-08 6:02 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 10:31
David Crow14-Apr-08 10:31 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 4:30
David Crow14-Apr-08 4:30 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 5:33
Larry Mills Sr14-Apr-08 5:33 
QuestionRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 5:39
David Crow14-Apr-08 5:39 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 6:05
Larry Mills Sr14-Apr-08 6:05 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow14-Apr-08 10:36
David Crow14-Apr-08 10:36 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr14-Apr-08 10:43
Larry Mills Sr14-Apr-08 10:43 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
David Crow15-Apr-08 9:18
David Crow15-Apr-08 9:18 
GeneralRe: No hwnd, ie hwnd = 00000000 using CMonthCalendar Control Pin
Larry Mills Sr15-Apr-08 12:30
Larry Mills Sr15-Apr-08 12:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.