i_luv_c++ 26 Light Poster

Hey guys! I am working on a project using single linked list and currently on the last task which is overloading the += operator. My merge from a+=b is inefficient because I am having a memory link problem and its slow when it used in list size of 100000. Please let me know if you guys see a error. Thanks for all the help!

//overloaded plus equal (+=) operator
	OList & operator += (const OList & other) { 
	
	Node<T> *temp,
			*p1 = head, //list on the left of operation a+=b
			* p2 = other.head;	//list on the right 
	
	size += other.size;	//change size of current list to list suze += right list size
	
	//data hold the data for the Node and next points to next node 
	while ( p2->next != NULL && p1->next != NULL ) {
		if (p1->next->data <= p2->next->data) {	
			p1= p1->next;	
			
		}
		else{temp = createNode(p2->next->data);
			temp->next = p1->next;
			p1->next = temp;
			p1 = p1->next;
			p2 = p2->next;
			}
	}
	while (p1->next != NULL) {
		p1 = p1->next;
	}
	while (p2->next != NULL) {
			p1->next = createNode(p2->next->data);
			p1 = p1->next;
			p2 = p2->next;
			if (p1->next == NULL) lastNode = p1;
		}
	lastNode = p1;
	return *this;
		
	}
i_luv_c++ 26 Light Poster

thanks for the shorted version of the code...However i still cnt figure out..so the basic idea is call the same function three times (numstones,1), (numstones,2), (numstones,3) and use that to predict the result for the n amount of stones. I have the idea just cnt figure out how to code it

i_luv_c++ 26 Light Poster

Hey Guys, I am writing a Recursive Function which picks the best move for Computer(sort of A.I.) i have done all the base cases however couldn't figure out how to deal with the last part.

Given n stones the player can remove 1, 2 or 3 stones per move. The player to remove the last stone loses. If a guaranteed win is possible, the function sets move to the winning move and returns true. If a win is not possible, the function returns false and sets move to 1 (a delaying tactic).

bool bestMove(int stonesLeft, int & move) {
	if (stonesLeft <= 4 && stonesLeft > 1)  {
		move = stonesLeft - 1;
		return true;
	}
	if (stonesLeft > 5) {
		return false;
		move =1;
	}
	if (stonesLeft == 1) {
		move =1;
		return false;
	}
	bestMove(stonesLeft -1, move);
}
i_luv_c++ 26 Light Poster

Hey guys,

I just reinstalled MS Visual Studio C++ Express and I am having this weird problem with the complier. So for example if I add a source file name file1 and run it it works fine..however if i delete the file1 from current project and add file2 it will still run file1 code on build/debugging. Why is it doing that? Any help would be great:) I need to finish my h.w. and visual studio is giving me headache with this wired problem

Thanks!

i_luv_c++ 26 Light Poster

hey guys,
i am working on a code..code runs fine however there is lot of input on the screen thus i am using a pause function to freeze the screen till user hits enter key. however function always skips the first time and works fine after that. i used cin.clear() but it still not clearing the old input steram. Again it only happens the first time.. after the first time it works fine. thanks for all the help

void pressEnter()
{
cin.clear(); // check for junk in the stream
cout << "\nPress Enter for more results";

//cin.ignore(); i tried this as well but same result
cin.get();
}
i_luv_c++ 26 Light Poster

hey guys i am trying to do one level of undo ..however its not working correctly..it does display the text but x and y axis gets messed up..any help and suggestion be great
thank you

void undo(pixeltype pixels[], int length, int option) {
	struct temp_pixels {
		int x;
		int y;
		char c;};
	temp_pixels temp[6000];
	if (option !=9) {		//copy one level of pixels location(x,y) 
		int i = 0;
		do {
			temp[i].x=pixels[i].x;
			temp[i].y=pixels[i].y;
			i++;
		}while(i<length);
	}
	else {		//run this if user picks UNDO in Menu
		int i = 0;
		do {
			pixels[i].x=temp[i].x;
			pixels[i].y=temp[i].y;
			i++;
			//pixels[i].c=temp[i].c;
		}while (i<length);
		drawImage(pixels,length);
		operations(menu(), pixels, length);
	}
	
}
i_luv_c++ 26 Light Poster

Hey guys,
I am working on a assignment. I am 90% done with the code. However I stuck on the part where i have to flip the output(vertically and horizontaly). I tried I everything i could. I tried setting the row up side down that way it would help and it does flip this way however the output spacing is incorrect. Anyhelp would be great
Thanks!

i_luv_c++ 26 Light Poster

omg i found it out...i can check it with the length of array...because we only want to repeat untill we have elements in the array...and thank you so much for your help...lesson of the day...for every bool function need to have a true and false...:)....

if(length<0)
		return false;
i_luv_c++ 26 Light Poster

i Just found one error...the length was incorrect...it says 5 and it should be 4..however program still dont run :/

i_luv_c++ 26 Light Poster

Thanks again for the reply..and finally the function make sense to me...however now every time i run the program it gets an error and stops the program...:(...if its possible for you can you pls try to run the program and see if it works..

#include <iostream>
using namespace std;
bool canMakeChange(int total, int nums[], int length){
	bool method1= canMakeChange(total,nums,length-1);
	bool method2= canMakeChange(total-nums[length-1],nums,length-1);
	
	if(method1 || method2)
		return true;
	else
		return false;


}
int main() 
{
	const int TOTAL = 20;
	int coins[4]={10,5,5,10};
	bool test =canMakeChange(TOTAL, coins, 4);
		if(test)	//cout true if change is possible
		cout<<"Yes, you can make change"<<endl;
                else
                   cout<<"Sorry cann't make change"<<endl;
		
	return 0;
}
i_luv_c++ 26 Light Poster

thanks for the reply..the logic is to find if it is possible to get correct change(total) by given coins(nums)....for example say u want 50 cent...(total) and nums are 10,10,10,20...thus bool would return true....there are two ways to check and see if the change(total could be made)..first is by taking out the last element from the array and adding the rest...second is taking of the last element and subtract that from the total. I been working on this all night but still couldnt figure it...any help be great...and another quick question since line 8 is infinit loop is it possible to run line 9 first and then line 8 would get the total from line 9???
and again thanks for all the help

i_luv_c++ 26 Light Poster

hey guys im new to recursion to recursion..pls look at the function call ...question is how do i call in two functions at the same time..and which one should i return
thank you.

#include <iostream>
using namespace std;
bool canMakeChange(int total, int nums[], int length){
if(total==0)
    return true;
    
else
	 canMakeChange(total,nums,length-1);
 return canMakeChange(total-nums[length-1],nums,length-1);

}
int main() 
{
	const int TOTAL = 20;
	int coins[4]={10,5,5,10};
	if (canMakeChange(TOTAL, coins, 5))
		cout<<"true"<<endl;
		
	return 0;
}
i_luv_c++ 26 Light Poster

hey guys my while loop is not working correctly..doesnt matter which character i enter it will still run the loop..and what it should do is test to see if character entered is 'y'(well thats what i want it to do )
thanks!!

#! /usr/bin/perl

$exp = "y";
while ($exp =="y") {
system "clear";         # clear the window

print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;

print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;

print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;

print "\nEnter the number of Doodats ordered: ";
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered
chop $doodatcount;

$widgetsub = $widgetcount * 10.25; #subtotal of widgets
"assignment4.pl" 67L, 2442C written                           
[cs41s1004@cc-ccs assignments]$ vi assignment4.pl
#! /usr
/bin/perl

$exp = "y";
while ($exp =="y") {
system "clear";         # clear the window

print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;

print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;

print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;

print "\nEnter the number of Doodats ordered: ";
$doodatcount = …
i_luv_c++ 26 Light Poster

thank you so much...:)

i_luv_c++ 26 Light Poster

hey guys i wrote a code for honework problem...the code works fine however everytime user puts more number than the static array it keep those number in the memory and later in the program if i do cout and cin it will ignore that and assign the number to the variable from the memory. Is it possible to delete all the extra input from the memory. For example my array has a maxvalue of 10 and if user enters 11 numbers it would keep that one number in memory and later when i try to do cout and ask the user to input a number it will automatically assign the 11th number???
thanks!

i_luv_c++ 26 Light Poster

hey guys im working on a project which requires two tasks
1) count the total number of clumps in a program which i already accomplished.
2)find the longest clump in the string and output it(for example if string is aaaabbbcccccccc so the longest clump is cccccccc

>>clump is string of letters>>For example if you pick the minimum clump length to be 2 than >>aaabcndxx<<has two clumps >>aaa<<and >>xx<< and longest clump is aaa .. I'm having trouble outputing the longest clump

#include <iostream>
#include <string>
using namespace std;
int countClumps(int k, string s, string & longest);
int main ()
{
	string string1, string2;
	int length;
	char play;
	do
	{
		cout << "Enter a minmum clump length of 2 or more: ";
		cin >> length;
		while (length <= 1)
		{
			cout << "ILLEGAL VALUE!!!!" << endl;
			cout << "Please Enter a minmum clump length of 2 or more:";
			cin >> length;
		}
		cout << "Enter one or more words each having at least ";
		cout << "2 characters. When you want to quit, enter any word with fewer than 2 characters." << endl;
		cin >> string1;
		cout << "total number of clumps: "countClumps(length, string1, string2) << endl;
		cout << "longest clump is " << string2 << endl;
		cout << "play again";
		cin >> play;
	}
	while (play != 'n');
	return 0;
}
int countClumps(int minimum_clump, string string1, string & longest)
{
	longest = "";	//to determine the longest clump
	
	int max = 1, min = 0, total …
Fbody commented: You already asked this in another thread. +0
i_luv_c++ 26 Light Poster

N clump is Letters which repeating.. For example if you pick the minimum clump length to be 2 than >>aaabcndxx<<has two clumps >>aaa<<and >>xx<< and longest clump is aaa .. I'm having trouble outputing the longest clump

i_luv_c++ 26 Light Poster

sorry guys my mistake actually I used my Iphone to paste the code.
so im trying to do two things with this code
first im trying to find the total number of clumps(which i already accomplished)

second the longest clump in the string(for example if user inputs>>>aabbb so output should be bbb...

#include <iostream>
#include <string>
using namespace std;
int countClumps(int k, string s, string & longest);
int main ()
{
	string string1, string2;
	int length;
	char play;
	do
	{
		cout << "Enter a minmum clump length of 2 or more: ";
		cin >> length;
		while (length <= 1)
		{
			cout << "ILLEGAL VALUE!!!!" << endl;
			cout << "Please Enter a minmum clump length of 2 or more:";
			cin >> length;
		}
		cout << "Enter one or more words each having at least ";
		cout << "2 characters. When you want to quit, enter any word with fewer than 2 characters." << endl;
		cin >> string1;
		cout << countClumps(length, string1, string2) << endl;
		cout << "longest clump is " << string2 << endl;
		cout << "play again";
		cin >> play;
	}
	while (play != 'n');
	return 0;
}
int countClumps(int minimum_clump, string string1, string & longest)
{
	longest = "";	//to determine the longest clump
	
	int max = 1, min = 0, total = 0;	//min and max counts the string to determine the clumps
	while (min < string1.length())
	{
		while (max < string1.length() && string1[min] == string1[max]) 
		{
			max++;
		}
		int total_clump = max - …
i_luv_c++ 26 Light Poster

hey guys im working on a homework problem which requires two things
-count the total number of clumps
-determine the longest clump
i finally made my code to recognize the number of total clumps however i still cnt figure out how to determine the longest clump
any help be great!thanks:)

#include <iostream>
#include <string>
using namespace std;
int countClumps(int k, string s, string & longest);
int main ()
{
	string s, string2;
	int length;
	char play;
	do
	{
		cout << "Enter a minmum clump length of 2 or more: ";
		cin >> length;
		while (length <= 1)
		{
			cout << "ILLEGAL VALUE!!!!" << endl;
			cout << "Please Enter a minmum clump length of 2 or more:";
			cin >> length;
		}
		cout << "Enter one or more words each having at least ";
		cout << "2 characters. When you want to quit, enter any word with fewer than 2 characters." << endl;
		cin >> s;
		cout << countClumps(length, s, string2) << endl;
		cout << "string2 is" << string2 << endl;
		cout << "play again";
		cin >> play;
	}
	while (play != 'n');
	return 0;
}
int countClumps(int k, string s, string & longest)
{
	longest = "";
	//  cout<<"long is" <<longest<<endl;
	int i = 1, g = 0, total = 0;
	while (g < s.length())
	{
		while (i < s.length() && s[g] == s[i])
		{
			i++;
		}
		int y = i - g;
		int p = g;
		if (y >= k)
			total++;
		if (y > longest.length()) …
i_luv_c++ 26 Light Poster

hey im new to linux...for a hw assingment im typing a document
and im trying to set the margin on the page...
i used the :set wrapmargin=1 cmd.
would that set the margin for the whole page? is it possible to set margin on each line?

i_luv_c++ 26 Light Poster

o o ok i didnt think of it this way..it makes sense now...thanks for making me aware of the && expression...:)

i_luv_c++ 26 Light Poster

thanks for clearing the cout statement for Goodbye!...works like magic..lol..hey i learned something new today...
however (a||b) make sense i understand both needs to be false
and i used the >>>while( word != "q" || word != "Q" );<<<
but i still cnt exit the loop:(...i wrote the loop on the paper which is if q is false run the loop again OR "Q" is false run the loop again...but somehow is still stuck in the loop...could that be because of string and char differences???

i_luv_c++ 26 Light Poster

thanks for the advice...however this is from what i have learned so far...in a do-while loop u cant put a statement after the final while loop???correct me if im wrong...
and for the while (word != "q" || word != "Q") if is set it to != i dnt know why but it s not terminating the program...even i tried while ((word != "q" || word != "Q")== 0) still only time i would actual terminate using q and Q is by while ((word == "q" || word == "Q") == 0); even though when i logically think about it its sayin when q is true do do the while loop but it does the opposite...if you can explain this to me that be great...i really want to know why its doing that...
thanks again

i_luv_c++ 26 Light Poster

thanks for all the help guys:)
i just modified the code and now it works
thanks again
here s the final code....pls let me know if you something looks wrong to guys
thanks again!!!

#include <iostream>
#include <string>
using namespace std;
bool isVowel(char c); // returns true if c is a vowel and false otherwise
int countVowels(string s); // returns the number of vowels in s.
int main ()
{
	string word;
	int answer;				//variable to store the final answer
	do						//do-while loop to play(restart) game
	{
		cout << "Please enter a word or 'q' to quit: ";
		cin >> word;
		if (word == "q" || word == "Q")	//terminate program if user enters q or Q
		{
			cout << "GoodBye!" << endl;
		}
		else
		{
			answer = countVowels(word);	//run the function countVowel and assign answer to asnwer variable
			cout << answer << endl;		//output total number of vowels
		}
	}
	while ((word == "q" || word == "Q") == 0);		//do while loop to repeat the program
	return 0;
}
int countVowels(string s)		//function to calucate the total vowals
{
	int i;
	int total = 0;
	for (i = 0; i < (s.length()); i++)	//loop to change char value and set max to string length s
	{
		if (isVowel(s[i]))		//if bool expression returned is true than add 1 to total
			total++;
	}
	return total;
}
bool isVowel (char c)	//check
{
	bool status;	//check with bool variale to see if char is vowel
	if …
i_luv_c++ 26 Light Poster

Still stuck I used ((word!="q")==0) it would run te program however if I use "q" it will not terminate the program :(

i_luv_c++ 26 Light Poster

o o sorry I didn't see the code u made ok so now it makes sense so I should make it ==0 to see if it's true :)

i_luv_c++ 26 Light Poster

Well it's a do while loop thus the way I coded it if while loop is not equal to q repeat the loop n if the string contains q than terminate the program .. But still if I use to strcmp it would compare two char values not a string and char .. I'm confused :((

i_luv_c++ 26 Light Poster

just replace 'q' with "q" and 'Q' with "Q". Still doesn't work, think about the logic in you comparision statement...

Still doesn't work I even tried to make second variable a string still doesn't work :(

i_luv_c++ 26 Light Poster

How about if I make 'q' a string and than do the comprasion using strcmp or is it possible to insert a bool variable to validate the while ? And thanks again for your help

i_luv_c++ 26 Light Poster

hey guys...my code is working fine..only problem i have is my first do-while loop doesnt work...every time i try to compare the word given by the user to 'q' ||'Q'...it gives an error saying no match for the operator..please help me ....thanks!

#include <iostream>
#include <string>
using namespace std;
bool isVowel(char c); // returns true if c is a vowel and false otherwise
int countVowels(string s); // returns the number of vowels in s.
int main ()
{
	string word;
	int answer;
	do
	{
		cout << "Please enter a word or 'q' to quit: ";
		cin >> word;
		answer = countVowels(word);
		cout << answer << endl;
	}
	while (word != 'q' || word != 'Q')
		return 0;
}
int countVowels(string s)
{
	int i;
	int total = 0;
	for (i = 0; i < (s.length()); i++)
	{
		if (isVowel(s[i]))
			total++;
	}
	return total;
}
bool isVowel (char c)
{
	bool status;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
		status = true;
	else
		status = false;
	return status;
}
i_luv_c++ 26 Light Poster

hey people:)
i have an old hard drive which contains some of my old homework projects...hard drive went bad a while back..everytime i run the hard drive its show the black and while screen ...is there is a way to fix it???
call me crazy but i tried the freezing method..and it didnt work :(...
thanks in advance:)

i_luv_c++ 26 Light Poster

thanks again guys..no i havent learned how to convert int to strings ...we just finished the chapter on if statements and teachers output had the comma so i thought maybe there is a function using if statement which allows you to do that..again thanks for the help:)

i_luv_c++ 26 Light Poster

sorry for not being clear guys...i want to display 160,000 (one-hundred-sixty-thousand)using a comma(,)...
a.dragon>> i am new to c++ so what you saying is use a head file "string" and convert the int variable to string variable ...along with that how would i use this >>std::string<<is this a function??or statement??

i_luv_c++ 26 Light Poster

hey guys im working on a homework problem..im done with 99% of the problem :|however i cnt figure out how to display my output(which is in dollars) using the comma
my output shows >>160000
how would i make it >>160,000
um should i use setprecision???
please help
thanks:)

i_luv_c++ 26 Light Poster

@ Lerner ... Hey thanks for the reply.. My code is working fine .. N I do understand the restriction part .. Maybe if I get some free time I try to figure out with LEss steps .. N again thanks to everyone whi replied :)

i_luv_c++ 26 Light Poster

@ VernonDozier
thank you so much for explaining...i sorted them the same way i would do in real life...step by step...and i worked..but i was just curious to know if there is any other way with less steps...and im new to c++ and thanks you and also dragon for pointing out the format errors...again thanks for the help :)

i_luv_c++ 26 Light Poster

hey guys thakns for all the help:)
i have a question about the nest??
if i use this code(code below >>>)..do i need to use only swap statement or do i need to use swap for each if statement??? and along with that when i tried to see compare d with a,b and c i had to go through 4 statement..is there is easy way???

if (a<b)
{
     if (b<c)
     {
         if (c<d)
          {
          swap(a,d)

and again thanks for your help!!!!:)

i_luv_c++ 26 Light Poster

hey guys..ok so i did this problem about 80% but i cnt figure out the last part which is sort the characters in order of increasing size.

Question:

Input: 4 words (strings with no spaces) and the order in which they are to be displayed, forward alphabetical, reverse alphabetical or in order of increasing size.

Output: the words in their selected order.

Sample run 1:

Please enter 4 words: wall table answer set
In what order would you like to display the words?
a: alphabetical order
r: reverse alphabetical order
s: in order of increasing size
Enter a, r or s: s
1) set
2) wall
3) table
4) answer


Sample run 2:

Please enter 4 words: wall table answer set
In what order would you like to display the words?
a: alphabetical order
r: reverse alphabetical order
s: in order of increasing size
Enter a, r or s: r
1) wall
2) table
3) set
4) answer

No arrays, programmer defined functions or loops. You may use if statements and/or switch statements in your code. Also, you may use the built-in swap() function

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main ()

{

	const int SIZE = 40;
	char first[SIZE], second[SIZE], third[SIZE], fourth[SIZE], order;
	cout<<"Please enter four words: ";
	cin>>first>>second>>third>>fourth;
	
	
	cout << "In what order …
Ancient Dragon commented: Thanks for using code tags correctly. +26
Fbody commented: next time, make it part of your original thread +0
i_luv_c++ 26 Light Poster

hey everyone i need help help with sorting chars
what im trying to do is show four words in order of increasing

sample run:
1) set
2) wall
3) table
4) answer

CNT use No arrays, programmer defined functions or loops. however can use built-in swap() function,if and or switch

Thanks :)