National University: CL-1002 Programming Fundamentals Lab # 13

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

National University

OfComputer&EmergingSciencesFaisalabad-ChiniotCampus

CL-1002
Programming
Fundamentals Lab # 13

Objectives:
• Practice and understanding on basic c++ programs
• One-dimensional Array
• Multi-dimensional Array

Note: Carefully read the following instructions (Each instruction contains a weightage)

1. Use proper font family (Calibri or Times New Roman) and font size of the title (16
points), heading (14 points), subheading (12 points), and normal text (10 points).
2. First think about the problem statement and then write/draw your logic on paper.
3. Microsoft Visual Studio should be used to make c++ programs. Programs
made with any other software would not be accepted.
4. For each task in the manual create a new C++ program with the naming convention as
follows:
TASK-NO
5. Mention what is happening in each line of code using comments.
6. Write all codes one by one with proper numbering and also paste screen shot of
each problem using the snipping tool (default screen capture software in windows)
on Microsoft word file.
7. Please submit your file with this naming convention
ROLLNO_SECTION_GROUPNO_LABNO.
8. Do not copy from any source otherwise, you will be penalized with zero marks.
9. Submit your lab on Google Classroom.

Page 1
National University
OfComputer&EmergingSciencesFaisalabad-ChiniotCampus

Problem: 1 | string

Write a program to input a sentence in string and then indicates the starting point (startIndex
and stopIndex). Now your program holds the section between the two indexes.
Example:
Entered string is “My name is Ali”
Start index: 4
Stop index: 7
Section between starting and Ending Index: name

Problem: 2 | String

Write a program in C++ that takes 5 to 10 lines as input text from the user and save it into a file
“myfile.txt”. Now write a code to count and display the number of lines not starting with
alphabet 'A'.
Example: Sample input: If the string contains the following lines,
The rose is red.
A girl is playing there.
There is a playground.
An airplane is in the sky.
Numbers are not allowed in the password.
Sample Output:
The rose is red.
There is a playground.
Numbers are not allowed in the password.
Count Value is: 3

Problem: 3 | C string

Given the declaration:


char str1[15];
char str2[15] = "Good day";
mark the following statements as valid or invalid. If a statement is invalid, explain
why.
a. str1 = str2;
b. if (str1 == str2)
cout << " Both strings are of the same length." << endl;
c. if (strlen(str1) >= strlen(str2))
str1 = str2;
d. if (strcmp(str1, str2) < 0)
cout << "str1 is less that str2." << endl;

Page 2
National University
OfComputer&EmergingSciencesFaisalabad-ChiniotCampus

Problem: 4 | C string

Given the declaration:


char str1[21];
char str2[21];
a. Write a C++ statement that stores "Sunny Day" in str1.
b. Write a C++ statement that stores the length of str1 into the int
variable length.
c. Write a C++ statement that copies the value of name into str2.
d. Write C++ code that outputs str1 if str1 is less than or equal to
str2, and otherwise outputs str2
Problem: 5 | C string

Assume the following declarations:


char name[21];
char yourName[21];
char studentName[31];
Mark the following statements as valid or invalid. If a statement is invalid, explain
why.
a. cin >> name;
b. cout << studentName;
c. yourName[0] = '\0';
d. yourName = studentName;
e. if (yourName == name)
studentName = name;
f. int x = strcmp(yourName, studentName);
g. strcpy(studentName, Name);
h. for (int j = 0; j < 21; j++)
cout << name[j];

Problem: 6 | C string

Write a program that prompts the user to input a string and outputs the string in uppercase
letters. (Use a character array to store the string.)

Problem: 7 | C string

Write a C++ Program to Swap Two String using Third variable.

Page 3
National University
OfComputer&EmergingSciencesFaisalabad-ChiniotCampus

Problem: 8 | C string

Write a C++ Program to Reverse an Array of Strings.


Problem: 9 | C string

Write a C++ Program to check whether a String is Palindrome or not.


Problem: 10 | C string

Write a C++ Program to input a string and then find the number of vowels in that string .

Best of luck

You are done with your exercise, submit on classroom at given time.

Page 4

You might also like