Assignment 04
Assignment 04
Assignment # 4
Subject: Introduction to Computing and AI Course Code: CS - 101 - I, F - 24
Class: BS DS– 1st Submission Deadline: 12/Dec/2024 - Thu (9:00 - AM)
Course Instructor: Ms. Nazia Shahzadi - Lecturer - Total Marks: 50 (Marks are divided problem-wise)
FCSE
Course TA’s: Ms. Basma
First, read the instructions and statements of each exercise/question carefully then write the solution.
• For Handwritten/Printed Form:
o In case of multiple questions, give the heading of each question’s number or the task you are going to
solve
o Mention the page number and your roll number at the corner of each page.
o Then select all pictures in the Cam scanner application and convert them into a PDF file.
o The name of your pdf file should contain your assignment number and your roll number as shown in the
following example, For Example, if your roll number is 2024532 and you have done assignment number 2
then the name of the file should be as → 2024532_2.pdf
o Then upload that pdf file to Microsoft Teams. Remember the sequence of pages should be right.
o Also submit the same original pages/hardcopy (in printed form) in Thursday’s class (21/11/2024).
CHEATING/COPY CASE or LATE SUBMISSION even 1 minute late will be resulted into MARKS
DEDUCTION .So be on time make no excuse.
Question#1 Points-10
Consider the following declaration: int list [] = {3, 8, 10, 13, 6, 11};
a. Write a C++code that will output the value stored in each component of list.
b. Write a C++ code that will set the values of the first five components of list as follows:
• The value of the ith component is the value of the ith component minus three times
the value of the (i+1)th component.
Question#2 Points-10
A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold each
month and reports it to the management at the end of the month. The management keeps the data
Page 1 of 2
in a file and assigns a number, 1 to 10, to each salesperson. The following statement declares an
array, cars, of 10 components of type int to store the number of cars sold by each salesperson:
int cars[10];
Write the code to store the number of cars sold by each salesperson in the array cars, output the
total numbers of cars sold at the end of each month, and output the salesperson number selling the
maximum number of cars.
Question#3 Points-10
Given the declaration:
char string15[16];
Mark the following statements as valid or invalid. If a statement is invalid, explain why.
a. strcpy(string15, "Hello there");
b. strlen(string15);
c. string15 = "Jacksonville";
d. cin >> string15;
e. cout << string15;
f. if (string15 >= "Nice day")
cout << string15;
g. string15[6] = 't';
Question#4 Points-10
Given an array with all integers between 1 and 100 except for one, find the missing number.
b. Correct the following code so that it correctly sets the value of each element of myList to
the index of the element.
Page 2 of 2