fork download
  1. // PartA.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <cstdlib> // for atoi(), atof()
  6. using namespace std;
  7.  
  8. // === Part A Tasks as functions ===
  9.  
  10. void task1() {
  11. cout << "Hello World!" << endl;
  12. }
  13.  
  14. void task2() {
  15. cout << "Hello World!" << endl;
  16. cout << "John Sleiman" << endl;
  17. cout << "s4005079" << endl;
  18. }
  19.  
  20. void task3() {
  21. int inputNumberOne = 5;
  22. int inputNumberTwo = 20;
  23. int sum = inputNumberOne + inputNumberTwo;
  24.  
  25. cout << "First input number: " << inputNumberOne << endl;
  26. cout << "Second input number: " << inputNumberTwo << endl;
  27. cout << "Sum: " << sum << endl;
  28. }
  29.  
  30. void task4(int argc, char* argv[]) {
  31. if (argc < 3) {
  32. cout << "Error: Please provide two integer arguments." << endl;
  33. return;
  34. }
  35.  
  36. int inputNumberOne = atoi(argv[1]);
  37. int inputNumberTwo = atoi(argv[2]);
  38. int sum = inputNumberOne + inputNumberTwo;
  39.  
  40. cout << "First input number: " << inputNumberOne << endl;
  41. cout << "Second input number: " << inputNumberTwo << endl;
  42. cout << "Sum: " << sum << endl;
  43. }
  44.  
  45. // Task 5 is the same as Task 4 (submit that file)
  46.  
  47. // Task 6 is environment related, can be omitted or mentioned in report.
  48.  
  49. int main(int argc, char* argv[])
  50. {
  51. // Uncomment the task you want to run:
  52.  
  53. // task1();
  54. // task2();
  55. // task3();
  56. task4(argc, argv);
  57.  
  58. return 0;
  59. }
  60.  
  61. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  62. // Debug program: F5 or Debug > Start Debugging menu
  63.  
  64. // Tips for Getting Started:
  65. // 1. Use the Solution Explorer window to add/manage files
  66. // 2. Use the Team Explorer window to connect to source control
  67. // 3. Use the Output window to see build output and other messages
  68. // 4. Use the Error List window to view errors
  69. // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  70. // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Success #stdin #stdout 0s 5308KB
stdin
5 20
stdout
Error: Please provide two integer arguments.