Hello, I recently did programming at school and what I thought was C was actually VBA/Pascal. I tried to change the VBA/Pascal to C++ but I couldn't does anybody know how to change this:
Sub P41()
Const Z = 26
Dim P(Z) As pr, tmp As pr, s As String, j As Integer, _
K As Integer, c As String, i As Integer
For K = 1 To Z 'we result in a standard data type pr
P(K).nm = Chr(Asc("a") + K - 1)
P(K).res = 0
Next K
Open "c:\Data\P41.txt" For Input As #1
Do While True
Line Input #1, s
If s = "*" Then Exit Do
s = LTrim(s) + " "
Do While Len(Trim(s)) > 0
c = LCase(Mid(s, 1, 1))
K = Asc(c) - Asc("a") + 1
P(K).res = P(K).res + 1
j = InStr(1, s, " ")
s = LTrim(Mid(s, j + 1))
Loop
Loop
For i = 1 To Z - 1
For j = 1 To Z - i
If P(j).res < P(j + 1).res Then
tmp = P(j)
P(j) = P(j + 1)
P(j + 1) = tmp
End If
Next j
Next i
For K = 1 To Z
If P(K).res > 0 Then
Debug.Print P(K).nm & " " & P(K).res
End If
Next K
Close #1
End Sub
program c4;
const delta = ord('a')-1;
var sum: array[1..26] of integer;
letters: array[1..26] of char;
s:string;
i,j,k,tmp:integer;
c:char;
begin
for i:=1 to 26 do
begin
sum[i] := 0;
letters[i] := chr(ord(i)+delta);
end;
s:='';
while s<>'*'do
begin
s := ' '+s;
for i:=1 to length(s)-1 do
begin
if (s[i]=' ') and (s[i+1]<>' ') then
inc(sum[ord(s[i+1])-delta]);
end;
readln(s);
end;
for k:=1 to 26 dofor j:=1 to 26-k do
begin
if sum[j]<sum[j+1] then
begin
tmp:=sum[j];
sum[j]:=sum[j+1];
sum[j+1]:=tmp;
c:=letters[j];
letters[j]:=letters[j+1];
letters[j+1]:=c;
end;
end;
i:=1;
for i:=1 to 26 do
begin
if sum[i]>0 then
writeln(letters[i],' ', sum[i]);
end;
readln;
end;
"You need to write a text analysis program. At the input of the program are given lines containing English words. In one line there can be an arbitrary number of words. All words are written in small (small) English letters. Between words in a line there can be one or more spaces, there may be spaces at the beginning and end of the line. Other characters, except for lowercase English letters and spaces, are not in the lines. The length of each line does not exceed 200 characters. The number of rows is unknown, the total number of words is not more than one million. The end of the input is indicated by a line containing a single character "*".
Write an effective, including a memory, program that will determine the number of words starting with each letter of the English alphabet and output these quantities and the corresponding letters in descending order. If the number of words starting with any letters is the same, these letters should be displayed in alphabetical order. If there is no letter for any letter, you do not need to output this letter.
The size of the memory that your program uses should not depend on the size of the source list.
Before the text of the program, briefly describe the algorithm of solving the problem used by you and indicate the programming language and version used.
Example input:
one two three four five
a quick brown fox
*
Example output for the above input example:
f 3
t 2
a 1
b 1
about 1
q 1
Note. The English alphabet is the same as Latin and contains 26 letters from a to z:
you can probably convert pascal directly to c++. Its not fun, but pascal is really compiled pseudocode based off procedural c++ type languages. begin and end become {}. procedure becomes void function, function becomes typed function, stuff like that. Its not that different. Null is nil.
basic is a whole nother mess. A re-write is in order.
I would bet you could even make a pascal to C translater with yacc or lex or something like those (or whatever the modern version is).