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 actually a statement used for outputting strings, the values of variables, and anyother thing that you want to be displayed on the screen. following is the syntax of cout statement. cout<<"String"; cout<<variable/arrays/structure variables; Note: / means that you can use any one of them. cout<<variable1<<variable2<<variable3; cout<<"string 1"<<varibale1<<"string 2"; note: we can use any combination of variables and strings we want. The << operator takes value from the variable and transfer it to cout which sends it to the output device normally the monitor using a stream called the output stream. Thanx, Ghulam Nasir(Khan) NIIT Cout is actually a statement used for outputting strings, the values of variables, and anyother thing that you want to be displayed on the screen. following is the syntax of cout statement. cout<<"String"; cout<<variable/arrays/structure variables; Note: / means that you can use any one of them. cout<<variable1<<variable2<<variable3; cout<<"string 1"<<varibale1<<"string 2"; note: we can use any combination of variables and strings we want. The << operator takes value from the variable and transfer it to cout which sends it to the output device normally the monitor using a stream called the output stream. Thanx, Ghulam Nasir(Khan) NIIT
void swap(int &a,int &b) { a=a+b; b=a-b; a=a-b; } int main(void) { int a,b; cout<<"Enter the value for a and b"; cin>>a>>b; cout<<"Before swapping"<<endl; cout<<"A= "<<a<<"B= "<<b; cout<<After swapping"<<endl; swap(a,b); cout<<"A= "<<a<<"B= "<<b; 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."; }
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.
It means that you are writing code computer generates different names for x and X, also it will understand commands or will not under stand it at all (c++: cout and Cout are different).
// 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; }
cin and cout are iostream objects, not keywords.
#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(); }
#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; }
#include <iostream> using namespace std; int main() { int x=5, y=10; cout << "Before:" << endl; cout << "x=" << x << " y=" << y << endl; // swap x and y values. x ^= y ^= x ^= y; cout << "After:" << endl; cout << "x=" << x << " y=" << y << endl; return( 0 ); }