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

Name: Maisam Rizvi ROLL NUMBER: 2019-CS-057 Section B: Code

The document contains code from two lab assignments. The first lab assignment involves taking input from the user and counting the frequency of each alphabet. The second lab assignment involves creating and reading from files.

Uploaded by

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

Name: Maisam Rizvi ROLL NUMBER: 2019-CS-057 Section B: Code

The document contains code from two lab assignments. The first lab assignment involves taking input from the user and counting the frequency of each alphabet. The second lab assignment involves creating and reading from files.

Uploaded by

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

NAME: MAISAM RIZVI

ROLL NUMBER: 2019-CS-057


SECTION B

Lab # 01
CODE;

#include <iostream>

#include <stdio.h>

#include <conio.h>

#include <string>

using namespace std;

int main() {

char str[10];

for (int i = 0; i < 10; i++)

cout<<"enter the alphabet:"<<endl;

cin>>str[i];

cout<<"the alphabet "<<str[i]<<" is pressed."<<endl;

}
int i = 0, alphabet[26] = {0}, j;

while (str[i] != '\0') {

if (str[i] >= 'a' && str[i] <= 'z') {

j = str[i] - 'a';

++alphabet[j];

++i;

cout<<"Frequency of all alphabets in the string is:"<<endl;

for (i = 0; i < 26; i++)

cout<< char(i + 'a')<<" : "<< alphabet[i]<< endl;

getch();

return 0;

Lab # 02
TASK 1

CODE;

#include <iostream>

#include <fstream>

using namespace std;

int main() {

fstream my_file;
my_file.open("my_file.txt", ios::out);

if (!my_file) {

cout << "File not created!";

else {

cout << "File created successfully!";

my_file << "MAISAM RIZVI";

my_file.close();

return 0;

TASK 2

CODE;

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main()

string path;

ifstream inFile(path);
cout << "Enter path of file: ";

cin >> path;

inFile.open(path);

if(inFile.is_open())

cout << "Found file\n";

else

cout << "Could not find file\n";

inFile.close();

system("PAUSE");

return 0;

OUTPUT;

TASK 3

CODE;

#include<iostream>
using namespace std;

int main()

string str1 ="This is I";

string str3= "MAISAM RIZVI";

cout <<"Before replacement, String is "<<str1<<'\n';

str1.replace(8,1,str3,0,4);

cout<<"After replacement,String is "<<str1<<'\n';

return 0;

You might also like