0% found this document useful (0 votes)
12 views5 pages

Lect 8

This document contains information about a computer programming course at Menoufia University's Faculty of Electronic Engineering. It includes the course objectives which cover basic C++ concepts like functions, macros, arrays, strings, object-oriented programming, classes, inheritance. It also provides contact information for the course instructor Dr. Ahmed Hamdy Ahmed Arafa and includes code examples of using arrays of strings in C++ programs, with one example printing the names and lengths of an array of student names and another example also calling a function to print the frequency of each name.

Uploaded by

Mazen Elsherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Lect 8

This document contains information about a computer programming course at Menoufia University's Faculty of Electronic Engineering. It includes the course objectives which cover basic C++ concepts like functions, macros, arrays, strings, object-oriented programming, classes, inheritance. It also provides contact information for the course instructor Dr. Ahmed Hamdy Ahmed Arafa and includes code examples of using arrays of strings in C++ programs, with one example printing the names and lengths of an array of student names and another example also calling a function to print the frequency of each name.

Uploaded by

Mazen Elsherif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Menoufia University

Faculty of Electronic Engineering

CSE 121: Computer Programming

Dr. Ahmed Hamdy Ahmed Arafa


Computer Science & Engineering Dept
Email: [email protected]
Mobile: +201020069729
Office: CSE Building 4th floor, Room 413
Course Objectives

✓ Overview of basic concepts of C++


✓ Functions in C++
✓ Macros in C++
✓ Arrays and Strings in C++
✓ Overview of basic concepts of object oriented programming in C++
✓ Classes and Objects in C++
✓ Inheritance in C++
Array of strings in C++.
#include<iostream> Print an array contains the names of a set of students and the number of
using namespace std; characters in each name.
int main()
{
string names[5] = {"ali", "ahmed","mostafa“}; #include<iostream>
cout<<"Names :\n"; using namespace std;
for (int i = 0; i< 5; i++) int main()
cout << names[i] << "\n"; {
} int n;
cout<<"Enter The number of students"<<endl;
cin>>n;
cin.ignore();
string names[n];
cout<<"Enter the names of students"<<endl;
for(int i=0; i<n;i++)
{
getline(cin,names[i]);
}
cout<<"Names\t\tLength"<<endl;
cout<<"----------------------"<<endl;
for (int i = 0; i< 5; i++)
cout << names[i]<< "\t\t"<<names[i].length()<<endl;

}
Array of strings in C++ (cont.)
Print an array contains the names of a set of students and the number of characters in
#include<iostream>
each name. Also write and call function that print number of repletion of each name.
using namespace std;
void print_frequency(string names[], int n)
{ int main()
int frequency[n]; {
int visited =-1; int n;
for(int i = 0; i <n; i++) cout<<"Enter The number of students"<<endl;
{
cin>>n;
int count = 1;
for(int j = i+1; j < n; j++)
cin.ignore();
{ string names[n];
if(names[i] == names[j]) cout<<"Enter the names of students"<<endl;
{ for(int i=0; i<n;i++)
count++; {
frequency[j] = visited;
getline(cin,names[i]);
}
}
}
if(frequency[i] != visited) cout<<"Names\t\tLength"<<endl;
frequency[i] = count; cout<<"----------------------"<<endl;
} for (int i = 0; i< 5; i++)
cout<<"\n\nNames\t\tFrequency"<<endl; cout << names[i]<< "\t\t"<<names[i].length()<<endl;
cout<<"----------------------"<<endl;
for(int i = 0; i < n; i++)
{
print_frequency(names,n);
if(frequency[i] != visited) return 0;
cout<< names[i]<<"\t"<<frequency[i]<<endl; }
}
}
Any Questions?????

You might also like