

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This Introduction to C++ Programming practice guide is designed to help students build a strong foundation in programming concepts through structured exercises with correct answers. It covers essential topics such as variables, data types, control structures, loops, functions, arrays, and basic object-oriented programming principles. Each exercise is designed to reinforce understanding and improve coding logic and problem-solving skills. Ideal for beginners and students preparing for exams, this guide simplifies complex programming concepts into clear, step-by-step explanations to support learning, revision, and practical coding success in C++.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


#in lude๐ using namespa e๐ std; int main() { int num1, num2; // de lare๐ variables ๐ out << "Enter two integers: \t"; // prompt user ๐in >> num1 >> num2; // read values from keyboard // output the results ๐ out << "The sum is: \t\t" << num1 + num2 << "\n" << "The produ t๐ is: \t" << num1 * num2 << "\n" << "The differen e๐ is: \t" << num
#in lude๐ using namespa e๐ std; int main() { int num1, num2; // de lare๐ variables ๐ out << "Enter two integers: "; // prompt user ๐in >> num >> num2; // read values from keyboard // Compares if values of "num1" and "num2" are equal if (num1 == num2) // If ๐ondition is true, then ๐out << "These numbers are equal." << endl; if (num1 > num2) // If ๐ondition is true, then ๐ out << num1 << " is larger." << endl; if (num2 > num1) // If ๐ondition is true, then ๐ out << num2 << " is larger." << endl; return 0; //indi ate๐ su ๐๐essful termination
#in lude๐ WWusi ngWnamespa e๐ Wstd;WintWmai n()W{ intWnum1,Wnum2,Wnum3,Wsmallest,Wlargest;W//de lare๐ WvariablesW ๐out W <>Wnum1W>>Wnum2W>>Wnum3;W//readWvaluesWfromWkeyboardWlargestW=Wn um1;W//WassumeW"num1"WisWtheWlargest ifW(num2W>Wlargest)W//isW"num2"WlargerWthanW"largest"?WlargestW=Wnu m2;W//WthenW"num2"WisWtheWlargest ifW(num3W>Wlargest)W//isW"num3"WlargerWthanW"largest"?WlargestW=Wnu m3;W//WthenW"num3"WisWtheWlargest smallestW=Wnum1;W//WassumeW"num1"WisWtheWsmallest ifW(num2W using namespa e๐ std; int main() { int num; // de lare๐ variable ๐ out << "Enter a number: "; // prompt user ๐ in >> num; // read value from keyboard if ((num % 2) == 0) // If "num" is even, then ๐ out << "The number " << num << " is even." << endl; if ((num % 2) != 0) // If "num" is odd, then ๐ out << "The number " << num << " is odd." << endl; return 0;