You are on page 1of 5

Menoufia University

Faculty of Electronic Engineering

CSE 121: Computer Programming

Dr. Ahmed Hamdy Ahmed Arafa


Computer Science & Engineering Dept
Email: ahmed.arafa@el-eng.menofia.edu.eg
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