双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

EE308 LAB1-2

激动的小马劈叉 激动的小马劈叉 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
The Link Your ClassMy class link
The Link of Requirement of This AssignmentLAB 1-2
The Aim of This AssignmentKeywords extraction and counting
MU STU ID and FZU STU ID20122187 832001215

Github :link to Github

目录

1.PSP form

2.Description of problem-solving ideas

3. Design and implementation process

4.code

5.output

6.summary


 

1.PSP form

PSPESTIMATE TIME(MINUTE)ESTIMATE TIME(MINUTE)
Planning3045
Estimate8060
Development4030
Analysis1520
Design Spec1010
Design Review105
Coding Standard1010
Design6030
Coding120150
Code Review510
Test6060
Reporting2020
Test Report1020
Size Measurement55
Postmortem & Process Improvement Plan55
Total480490

2.Description of problem-solving ideas

       Because I am familiar with c++ , I plan to use c++ to solve this problem 

       I plan to divide this project into the following five parts.

       1.Read the file and save it in a string array.

       2.Using the getline function  to spilt each word.

       3.Using the find function to determine the keywords and count keywords.

       4.Determine the output result based on the conditions.

       5.Do unit testing.

3. Design and implementation process

 

4.code

 

(1)initialize and enter keywords

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    int count_keyword=0;//the number of keyword
    int count_switch=0;//the number of switch
    int count_switch_case[100]={0};//to store the number of case in each switch
    int count_if_else=0;//the number of if-else structure
    int count_if_elseif_else=0;//the number of if-elseif-else structure
    int flag[100]={0};
    int level;
    string line;
    string filename;
    ifstream inFile;
    cout<<"Please input the file name: ";
    cin>>filename;
    cout<<"Please input the level: ";
    cin>>level;
    inFile.open(filename.c_str());
    //test if the file opens
    if(!inFile.is_open())
    {
        cout<<"The file was not successfully opened"<<endl;
        return 0;
    }
    string keyword[32]={"void","char","int","float","double","short","long","signed","unsigned",
        "struct","union","enum","typedef","sizeof","auto","static","register","extern","const","volatile",
        "return","continue","break","goto","if","else","switch","case","default","for","do","while"};

2. Main function realization

 

string str;
	int total=32,numt=0; ;
	int count[total] = {0}; 
	while (getline (inFile, str)){
		for(int i=0;i<total;i++){
		int pos;
		for(;;){
				if(str.find(keyword[i]) != -1){
					if(str.find("//") != -1) break;
					else{
						pos = str.find(keyword[i]);
						count[i]++;
						str = str.substr(pos + keyword[i].length(),str.length() - pos - keyword[i].length());
					}
				} 
				else break;
			}	
		}
	}
	for(int j=0;j<total;j++){
		if(count[j]!=0){
			numt+=count[j];	
		}
	}
	int num[5]={25,2,6,15,9},x[3]={0,0,-1};
	int struc[count[num[0]]]={0};
	string pick[3]={"else if", "if","else"};
	while (getline (s1, str)){
		int pos;
		for(;;){
			if(str.find(keyword[num[1]]) != -1){
				if(str.find("//") != -1) break;
				else{
					struc[x[0]]++;
					break;
				}
			}
			if(str.find(keyword[num[2]]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[0]++;
					break;
				}
			}
			if(str.find(pick[0]) != -1){
				pos = str.find(pick[0]);
				str = str.substr(pos + pick[0].length(),str.length() - pos - pick[0].length());
			}
			if(str.find(pick[1]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[1]++;
					break;
				}
			}
			else break;
		}	
	}
	int divide[x[1]]={0}, ely=0,eln=0;
	while (getline (s2, str)){
		int pos;
		for(;;){
			if(str.find(pick[0]) != -1){
				if(str.find("//") != -1) break;
				else{
					divide[x[2]]++;
					break;
				} 
			}
			if(str.find(keyword[num[3]]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[2]++;
					break;
				}
			}
			else break;
		}
	}
	for(int m=0;m<x[1];m++){
		if(divide[m]==0){
			eln++;
		}
		else{
			ely++;				
		}	
	}
	for(int o=1; o<con+1; o++){
		switch(o){
		case 1:
			cout<<"total num is: "<<numt<<endl;
			for(int j=0;j<total;j++){	
				if(count[j]!=0){
				cout<<keyword[j]<<" num: "<<count[j]<<endl;
				}
			}
			break;
		case 2:
			if(count[num[0]]!=count[num[2]]){
				cout<<" wrong switch structure"<<endl;
			}
			else{
				cout<<"The number of switch structure is:"<<count[num[0]]<<endl;
				for(int k=0;k<count[num[0]];k++){
				cout<<"switch "<<k+1<<" number of case is: "<<struc[k]<<endl;
			}
			}
			break;
		case 3:
			cout<<"the number of if-else: "<<eln<<endl;
			break;
		case 4:
			cout<<"the number of if-else if-else: "<<ely<<endl;
			break;
		default:
			cout<<"wrong"<<endl;
		}
	}
	inFile.close();
	s1.close();
	s2.close();
    return 0;
}

3.entire code

#include <string>
#include <iostream>
#include <fstream>
using namespace std;
string keyword[32]={"void","char","int","float","double","short","long","signed","unsigned",
        "struct","union","enum","typedef","sizeof","auto","static","register","extern","const","volatile",
        "return","continue","break","goto","if","else","switch","case","default","for","do","while"};
 
int main(){
	int con=0;
	string root; 
	cout<<"the .cpp file name you wanna in the same folder"<<endl;
	cin>>root;
	cout<<"what level of stastic you want(from 1 to 4)"<<endl;
	cin>> con;
	ifstream inFile,s1,s2;
	inFile.open(root.c_str(),ios::in);
	s1.open(root.c_str(),ios::in);
	s2.open(root.c_str(),ios::in);
	if(!inFile|| !s1 ||!s2){
        cout <<"Check the Path of File !" << endl;
        exit(0); 
    }
	string str;
	int total=32,numt=0; ;
	int count[total] = {0}; 
	while (getline (inFile, str)){
		for(int i=0;i<total;i++){
		int pos;
		for(;;){
				if(str.find(keyword[i]) != -1){
					if(str.find("//") != -1) break;
					else{
						pos = str.find(keyword[i]);
						count[i]++;
						str = str.substr(pos + keyword[i].length(),str.length() - pos - keyword[i].length());
					}
				} 
				else break;
			}	
		}
	}
	for(int j=0;j<total;j++){
		if(count[j]!=0){
			numt+=count[j];	
		}
	}
	int num[5]={25,2,6,15,9},x[3]={0,0,-1};
	int struc[count[num[0]]]={0};
	string pick[3]={"else if", "if","else"};
	while (getline (s1, str)){
		int pos;
		for(;;){
			if(str.find(keyword[num[1]]) != -1){
				if(str.find("//") != -1) break;
				else{
					struc[x[0]]++;
					break;
				}
			}
			if(str.find(keyword[num[2]]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[0]++;
					break;
				}
			}
			if(str.find(pick[0]) != -1){
				pos = str.find(pick[0]);
				str = str.substr(pos + pick[0].length(),str.length() - pos - pick[0].length());
			}
			if(str.find(pick[1]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[1]++;
					break;
				}
			}
			else break;
		}	
	}
	int divide[x[1]]={0}, ely=0,eln=0;
	while (getline (s2, str)){
		int pos;
		for(;;){
			if(str.find(pick[0]) != -1){
				if(str.find("//") != -1) break;
				else{
					divide[x[2]]++;
					break;
				} 
			}
			if(str.find(keyword[num[3]]) != -1){
				if(str.find("//") != -1) break;
				else{
					x[2]++;
					break;
				}
			}
			else break;
		}
	}
	for(int m=0;m<x[1];m++){
		if(divide[m]==0){
			eln++;
		}
		else{
			ely++;				
		}	
	}
	for(int o=1; o<con+1; o++){
		switch(o){
		case 1:
			cout<<"total num is: "<<numt<<endl;
			for(int j=0;j<total;j++){	
				if(count[j]!=0){
				cout<<keyword[j]<<" num: "<<count[j]<<endl;
				}
			}
			break;
		case 2:
			if(count[num[0]]!=count[num[2]]){
				cout<<" wrong switch structure"<<endl;
			}
			else{
				cout<<"The number of switch structure is:"<<count[num[0]]<<endl;
				for(int k=0;k<count[num[0]];k++){
				cout<<"switch "<<k+1<<" number of case is: "<<struc[k]<<endl;
			}
			}
			break;
		case 3:
			cout<<"the number of if-else: "<<eln<<endl;
			break;
		case 4:
			cout<<"the number of if-else if-else: "<<ely<<endl;
			break;
		default:
			cout<<"wrong"<<endl;
		}
	}
	inFile.close();
	s1.close();
	s2.close();
    return 0;
}

3.test code

#include <stdio.h>  
int main(){  
    int i=1;  
    double j=0;  
    long f;  
    switch(i){  
        case 0:  
            break;  
        case 1:  
            break;  
        case 2:  
            break;  
        default:  
            break;  
    }  
    switch(i){  
        case 0:  
            break;  
        case 1:  
            break;  
        default:  
            break;  
	    }  
	if(i<0){  
        if(i<-1){}  
        else{}  
    }  
    else if(i>0){  
        if (i>2){}  
        else if (i==2) {}  
        else if (i>1) {}  
        else {}  
    }  
    else{  
        if(j!=0){}  
        else{}  
    }  
    return 0;  
}  

5.output

 

6.summary

   Through this experiment, I am more familiar with the writing method of c++ code, and have a deeper understanding of logical statements. In addition, I learned more about how to use Github and CSDN. I realize that planning is very important. At the same time, I realize that I have some shortcomings in programming. I will improve myself in the future.

  

 

 

...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

研发流程后端开发工具,提示功能开发效率

后端开发工具

阳光不锈@

Screenshot_2026-11-03-16-23-09-34.jpg

Screenshot_2026-11-03-16-23-09-34.jpg

2601_97129411

机器人具有扰动抑制功能的有限时间基于方位角的领航者-跟随者编队控制(Matlab代码实现)

内容概要:本文档标题为《Plecs全桥LLC谐振变换器仿真模型.txt》,但实际内容并未涉及该主题的具体技术细节或仿真建模过程。相反,文档实质是一份由科研服务团队发布的跨学科资源目录,集中展示了大量基于Matlab、Simulink、Python、PSCAD等平台实现的科研项目与算法开发案例,涵盖电力系统、无人机路径规划、微电网优化、状态估计、信号处理、车间调度、图像处理、通信技术、雷达追踪、智能优化算法等多个工程技术领域。每个条目以“【】”标注研究主题,并注明“Matlab代码实现”“Python代码实现”等形式,表明其为可提供技术支持与代码资源的服务项目。文档末尾频繁出现“完整资源下载:公众号——荔枝科研社”及百度网盘链接,明确体现出其作为科研辅助服务推广与引流工具的功能属性。; 适合人群:面向电气工程、自动化、控制科学与工程、计算机科学、智能制造、新能源、航空航天、通信工程及相关交叉学科的研究生、高校教师、科研人员及企业研发工程师。; 使用场景及目标:①为科研人员提供课题选题、技术路线设计与算法实现的参考范例;②辅助学生或研究人员完成课程设计、毕业论文、项目仿真与算法复现任务;③作为第三方技术服务团队的能力展示目录,便于潜在客户快速了解其在多领域提供的定制化仿真与算法开发服务范围。; 阅读建议:此文档并非传统意义上的学术论文或技术教程,而是一份高度碎片化、广告性质浓厚的资源索引清单。读者应忽略其误导性的文件名,将其视为一个综合性科研技术服务目录,重点关注自身研究方向相关的条目,并通过文末提供的公众号或网盘链接进一步获取具体代码与资料。同时,需注意甄别资源的技术质量、原创性与适用性,避免盲目依赖外部服务。

荔枝科研社

科技中介服务机构如何打造高效、可复制的技术交易服务流程?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论
收藏 已收藏
分享
返回顶部