NO more unless you have not like caght zapdos.
the code for the box is: # include <iostream> using namespace std; void main () { cout << "*********\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*\t*\n"; cout << "*********\n"; the code for the oval is: # include <iostream> using namespace std; void main () { cout << " ***\n"; cout <<" * *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<"* *\n"; cout <<" * *\n"; cout << " ***\n"; the code for the arrow is: # include <iostream> using namespace std; void main () { cout << " * \n"; cout <<" ***\n"; cout <<"*****\n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; cout <<" * \n"; the code for the diamond: # include <iostream> using namespace std; void main () { cout << " *\n "; cout <<" * *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<"* *\n"; cout<<" * *\n"; cout<<" * *\n"; cout <<" * *\n"; cout << " *\n "; }
COUT is an inbuilt function in c++ language. Cout is used to print something on to the standard output.
This is an incomplete sentence, and "cout" is not a word.
A 'throw' statement throws an exception when it is generated within a try block. The exception is then caught by the corresponding catch block. For example, void somefn() { float m, n; try { cin>>m>>n; if (n == 0) throw(n); else cout<<(m/n); } catch (float x) { cout<<"Division by zero not possible"; } }
// Pointing // Demonstrates using pointers #include <iostream> #include <string> using namespace std; int main() { int* pAPointer; //declare a pointer int* pScore = 0; //declare and initialize a pointer int score = 1000; pScore = &score; //assign pointer pScore address of variable score cout << "Assigning &score to pScore\n"; cout << "&score is: " << &score << "\n"; //address of score variable cout << "pScore is: " << pScore << "\n"; //address stored in pointer cout << "score is: " << score << "\n"; cout << "*pScore is: " << *pScore << "\n\n"; //value pointed to by pointer cout << "Adding 500 to score\n"; score += 500; cout << "score is: " << score << "\n"; cout << "*pScore is: " << *pScore << "\n\n"; cout << "Adding 500 to *pScore\n"; *pScore += 500; cout << "score is: " << score << "\n"; cout << "*pScore is: " << *pScore << "\n\n"; cout << "Assigning &newScore to pScore\n"; int newScore = 5000; pScore = &newScore; cout << "&newScore is: " << &newScore << "\n"; cout << "pScore is: " << pScore << "\n"; cout << "newScore is: " << newScore << "\n"; cout << "*pScore is: " << *pScore << "\n\n"; cout << "Assigning &str to pStr\n"; string str = "score"; string* pStr = &str; //pointer to string object cout << "str is: " << str << "\n"; cout << "*pStr is: " << *pStr << "\n"; cout << "(*pStr).size() is: " << (*pStr).size() << "\n"; cout << "pStr->size() is: " << pStr->size() << "\n"; return 0; }
// Mad-Lib // Creates a story based on user input #include <iostream> #include <string> using namespace std; string askText(string prompt); int askNumber(string prompt); void tellStory(string name, string noun, int number, string bodyPart, string verb); int main() { cout << "Welcome to Mad Lib.\n\n"; cout << "Answer the following questions to help create a new story.\n"; string name = askText("Please enter a name: "); string noun = askText("Please enter a plural noun: "); int number = askNumber("Please enter a number: "); string bodyPart = askText("Please enter a body part: "); string verb = askText("Please enter a verb: "); tellStory(name, noun, number, bodyPart, verb); return 0; } string askText(string prompt) { string text; cout << prompt; cin >> text; return text; } int askNumber(string prompt) { int num; cout << prompt; cin >> num; return num; } void tellStory(string name, string noun, int number, string bodyPart, string verb) { cout << "\nHere's your story:\n"; cout << "The famous explorer "; cout << name; cout << " had nearly given up a life-long quest to find\n"; cout << "The Lost City of "; cout << noun; cout << " when one day, the "; cout << noun; cout << " found the explorer.\n"; cout << "Surrounded by "; cout << number; cout << " " << noun; cout << ", a tear came to "; cout << name << "'s "; cout << bodyPart << ".\n"; cout << "After all this time, the quest was finally over. "; cout << "And then, the "; cout << noun << "\n"; cout << "promptly devoured "; cout << name << ". "; cout << "The moral of the story? Be careful what you "; cout << verb; cout << " for."; }
#include<iostream.h> #include<conio.h> void main() { clrscr(); int marks; cout<<"Enter Marks of Student="; cin>>marks; cout<<"Grade\n"; if(marks>0 && marks<50) cout<<"F"; else if(marks>=50 && marks<55) cout<<"C-"; else if(marks>=55 && marks<60) cout<<"C"; else if(marks>=60 && marks<65) cout<<"c+"; else of(marks>=65 && marks<69) cout<<"B-"; else if(marks>=69 && marks<71) cout<<"B"; else if(marks>=71 && marks<75) cout<<"B+"; else if(marks>=75 && marks<79) cout<<"B"; else if(marks>=79 && marks<84) cout<<"A"; else cout<<"A"; getch(); }
cin and cout are iostream objects, not keywords.
#include<iostream.h> #include<process.h> #define SIZE 10 class Stack { private: int a[SIZE]; int top; public: Stack(); void push(int); int pop(); int isEmpty(); int isFull(); void display(); }; Stack::Stack() { top=0; } int Stack::isEmpty() { return (top==0?1:0); } int Stack::isFull() { return(top==SIZE?1:0); } void Stack::push(int i) { try { if(isFull()) { throw "Full"; } else { a[top]=i; top++; } } catch(char *msg) { cout<<msg; } } int Stack::pop() { try { if(isEmpty()) { throw "Empty"; } else { return(a[--top]); } } catch(char *msg) { cout<<msg; } return 0; } void Stack::display() { if(!isEmpty()) { for(int i=top-1;i>=0;i--) cout<<a[i]<<endl; } } int main() { Stack s; int ch=1; int num; while(ch!=0) { cout<<"1. push"<<endl <<"2. pop"<<endl <<"3. display"<<endl <<"0. Exit"<<endl; cout<<"Enter ur choice :"; cin>>ch; switch(ch) { case 0: exit(1); case 1: cout<<"Enter the number to push"; cin>>num; s.push(num); break; case 2: cout<<"a number was popped from the stack"<<endl; s.pop(); break; case 3: cout<<"The numbers are"<<endl; s.display(); break; default: cout<<"try again"; } } return 0; } #include<iostream.h> #define SIZE 10 class Queue { private: int rear; int front; int s[SIZE]; public: Queue() { front=0; rear=-1; } void insert(int); void del(); int isEmpty(); int isFull(); void display(); }; int Queue::isEmpty() { return(front>rear?1:0); } int Queue::isFull() { return(rear==SIZE?1:0); } void Queue::insert(int item) { try { if(isFull()) { throw "Full"; } else { rear=rear+1; s[rear]=item; } } catch(char *msg) { cout<<msg; } } void Queue::del() { int item; try { if(isEmpty()) { throw "Empty"; } else { item=s[front]; front=front+1; cout<<"\n DELETED ELEMENT IS %d\n\n"<<item; } } catch(char *msg) { cout<<msg; } } void Queue::display() { cout<<"\n"; for(int i=front;i<=rear;i++) { cout<<s[i]<<"\t"; } } int main() { int ch; Queue q; int item; do { cout<<"\n\n1.INSERTION \n"; cout<<"2.DELETION \n"; cout<<"3.EXIT \n"; cout<<"\nENTER YOUR CHOICE : "; cin>>ch; switch(ch) { case 1: cout<<"\n\t INSERTION \n"; cout<<"\nENTER AN ELEMENT : "; cin>>item; q.insert(item); q.display(); break; case 2: cout<<"\n\t DELETION \n"; q.del(); q.display(); break; } }while(ch!=3); return 0; }
#include<iostream> int main() { std::cout << "Truth table for AND gate\n\n"; std::cout << " |0 1\n"; std::cout << "-+---\n"; for (unsigned a=0; a<2; ++a) { std::cout << a << '|'; for (unsigned b=0; b<2; ++b) { std::cout << (a & b) << ' '; } std::cout << '\n'; } std::cout << std::endl; }
The following example demonstrates all 4 loop structures in C++. #include<iostream> int main() { int i; std::cout<<"For loop...\n"<<std::endl; for(i=0; i<10; ++i) std::cout<<i; std::cout<<'\n'<<std::endl; std::cout<<"While loop...\n"<<std::endl; i=0; while(i<10) std::cout<<i++; std::cout<<'\n'<<std::endl; std::cout<<"Do-while loop...\n"<<std::endl; i=0; do { std::cout<<i; }while( ++i<10 ); std::cout<<'\n'<<std::endl; std::cout<<"Goto loop...\n"<<std::endl; i=0; again: std::cout<<i; if(++i<10) goto again; std::cout<<'\n'<<std::endl; } Output: For loop... 0123456789 While loop... 0123456789 Do-while loop... 0123456789 Goto loop... 0123456789
#include<iostream.h> void main() { cout<<' '<<' '<<"a"<<'\n'; cout<<' '<<"a"<<"b"<<"a"<<'\n'; cout<<'a'<<'b'<<'c'<<'b'<<'a'<<"\n"; }