Today’s day is very special for all lovers. So I thought that I should share some programming stuff that show Valentine’s Day feeling. A C++ program is given below which prints heart shape with a Happy Valentine’s Day message inside it. If you want, you can change the message by changing the value of string message. I hope that you will like this.
#include<iostream> #include<cmath> using namespace std; int main() { double x, y, size=10; char ch=3; string message(" Happy Valentine's Day "); int print_line = 4; if(message.length() % 2 != 0) message += " "; for(x=0;x<size;x++) { for(y=0;y<=4*size;y++) { double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) ); double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) ); if (dist1 < size + 0.5 || dist2 < size + 0.5 ) { cout<< ch; } else cout<< " "; } cout<<"\n"; } for(x=1;x<2*size;x++) { for(y=0;y<x;y++) cout << " "; for (y=0;y<4*size + 1 - 2*x; y++) { if (x>= print_line - 1 && x <= print_line + 1) { int idx = y - (4*size - 2*x - message.length()) / 2; if(idx < message.length() && idx >= 0) { if (x == print_line) cout<<message[idx]; else cout << " "; } else cout << ch; } else cout<< ch; } cout<<endl; } return 0; }
Output
string message("happy valentine's day"); is showing error …..undefined symbol message.
String is a data type which is introduced in modern compilers. It will work fine in GCC. Which compiler you are using? If it is not working is your compiler then change message to a character array.
I am using turbo c++ ….and i use to change it in character array but is still not working and the header file is also not opening..
I also get the error.please tell me the how i will remove the error i wiill use the turbo C++.
Try below code its working fine, just add header files iostream.h, conio.h, math.h and string.h because it is not displaying in the comment.
#include
#include
#include
#include
int main()
{
double x, y, size=10;
char ch=3;
char message[]=" Happy Valentine's Day ";
int print_line = 4,len;
len=strlen(message);
for (x=0;x= print_line – 1 && x <= print_line + 1) {
int idx = y – (4*size – 2*x – len) / 2;
if (idx < len && idx >= 0) {
if (x == print_line) cout<<message[idx];
else cout << " ";
}
else cout << ch;
}
else cout << ch;
}
cout<<endl;
}
getch();
return 0;
}
lots of error generated….
it's awesome
It was not executing I’m struck up with this
sir, i want (u) shape print patern.
i am using turbo c++ after compiling this program it says “must use c++ for the type iostream….”
Hi,
Can you please explain how did you derive below equation?
1. double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );
2. dist1 < size + 0.5 || dist2 = print_line – 1 && x <= print_line + 1) {
int idx = y – (4*size – 2*x – message.length()) / 2;
Thanks,
Neeraj
Hi,
Can you please explain all this code for me?
Thanks,
Huy
coding skill for c++ language