• Home
  • Swinburne University of Technology
  • fundamental of programmimg
  • Variable Declarations and Basic Programming Tasks

Variable Declarations and Basic Programming Tasks

COS10029 - Fundamentals of Programming SWIN BUR · NE . SWINBURNE UNIVERSITY OF TECHNOLOGY COS10029 - Fundamentals of Programming Week 2 - Lab exercises (Submit all three tasks in Canvas). Task 2.1 The purpose of this task is to demonstrate your knowledge of variable declarations, assigning values to them, and reading and manipulating them in a program. Submission Requirement 1. Source code 2. Screenshot of the output An example 1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 int main() 7 8 string name; 9 int current_year; int age, year_born; 10 11 12 cout << "What is your name? "; cin >> name; cout << "Your name is: " << name << endl; 13 14 15 16 cout << "Enter current year: "; cin >> current_year; cout << "How old are you? "; cin >> age; 17 18 19 20 21 year_born = current_year - age; cout << name << " was born in year " << year_born << endl; 22 23 24 25 return 0; Output for example code rajik@DESKTOP-4310VNQ MINGW64 /c/Users/rajik/Desktop/Prince TP1 2020/TP1_2023/COS10029/Week2 $ g++ Task2. 1_Example. cpp -o output rajik@DESKTOP-431OVNQ MINGW64 /c/Users/rajik/Desktop/Prince TP1 2020/TP1_2023/COS10029/Week2 $ . /output. exe What is your name? Peter Your name is: Peter Enter current year: 2023 How old are you? 23 Peter was born in year 2000 @Copyright: Swinburne University of Technology Week 2 Lab CRICOS: 0011D TOID: 3059 Page 1 of 7 COS10029 - Fundamentals of Programming Task 2.1 - Question Open any text editor and create a program (Task2.1.cpp) using the pseudo-code given below. SWIN BUR · NE * SWINBURNE UNIVERSITY OF TECHNOLOGY Function: Main Variables: - name (to store the name of the student) - total_mark(to store an integer for total mark) - mark_lost (to store a float value for the marks lost by the student) - grade(to store a grade, Distinction, Credit or Pass) - mark (to store a float value) Steps: 1: Read the student's name (use cin). 2: Read the student's total mark (an integer, prompt with "Please enter student's total mark" ) and store it in the total_mark variable. 3: Read the marks lost by the student (a float, prompt with "Please enter the marks lost by the student:) and store it in the mark_lost variable. 4: Read the grade (a string, prompt with "What is the grade?) and store it in the grade variable. 5: Calculate the marks scored by the student (total_mark - mark_lost), and store it in the mark variable 6: Output the message, "The student has scored marks and got a ..... grade" 2. Open a terminal window, and compile your program using the following commands: . Change into the directory which contains your code using the cd command. · Compile the program using the following command. g++ Task2.1.cpp -o output · Run your program using ./ output 3. Submit the source code and the screenshot of the output window. Task 2.2 Drawing shape Create a custom picture drawing (any meaningful drawing) program using SplashKit Software Development